whyclxw
2025-01-16 60eefffd2a9a32d870d554a3790bd68c5546cdf3
首页统计
3个文件已添加
2个文件已修改
279 ■■■■ 已修改文件
src/main/java/com/whyc/mapper/LockReportMapper.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/pojo/db_lock_ram/LockReport.java 93 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/AreaInfService.java 100 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/service/LockReportService.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/webSocket/HomeSocket.java 54 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/mapper/LockReportMapper.java
New file
@@ -0,0 +1,6 @@
package com.whyc.mapper;
import com.whyc.pojo.db_lock_ram.LockReport;
public interface LockReportMapper extends CustomMapper<LockReport>{
}
src/main/java/com/whyc/pojo/db_lock_ram/LockReport.java
New file
@@ -0,0 +1,93 @@
package com.whyc.pojo.db_lock_ram;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
 * <p>
 * 电子锁开锁次数统计表
 * </p>
 *
 * @author lxw
 * @since 2025-01-16
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName(schema = "db_lock_ram",value ="tb_lock_report")
@ApiModel(value="LockReport对象", description="电子锁开锁次数统计表")
public class LockReport implements Serializable {
    private static final long serialVersionUID = 1L;
    @ApiModelProperty(value = "自增主键")
    @TableId(value = "num", type = IdType.AUTO)
    private Long num;
    @ApiModelProperty(value = "锁具ID号")
    private Integer lockId;
    @ApiModelProperty(value = "统计年份")
    private Integer recordYear;
    @ApiModelProperty(value = "1月开锁次数")
    private Integer month1;
    @ApiModelProperty(value = "2月开锁次数")
    private Integer month2;
    @ApiModelProperty(value = "3月开锁次数")
    private Integer month3;
    @ApiModelProperty(value = "4月开锁次数")
    private Integer month4;
    @ApiModelProperty(value = "5月开锁次数")
    private Integer month5;
    @ApiModelProperty(value = "6月开锁次数")
    private Integer month6;
    @ApiModelProperty(value = "7月开锁次数")
    private Integer month7;
    @ApiModelProperty(value = "8月开锁次数")
    private Integer month8;
    @ApiModelProperty(value = "9月开锁次数")
    private Integer month9;
    @ApiModelProperty(value = "10月开锁次数")
    private Integer month10;
    @ApiModelProperty(value = "11月开锁次数")
    private Integer month11;
    @ApiModelProperty(value = "12月开锁次数")
    private Integer month12;
    @ApiModelProperty(value = "第一季度开锁次数")
    private Integer quarter1;
    @ApiModelProperty(value = "第二季度开锁次数")
    private Integer quarter2;
    @ApiModelProperty(value = "第三季度开锁次数")
    private Integer quarter3;
    @ApiModelProperty(value = "第四季度开锁次数")
    private Integer quarter4;
    @ApiModelProperty(value = "本年开锁次数")
    private Integer yearCount;
}
src/main/java/com/whyc/service/AreaInfService.java
@@ -12,6 +12,7 @@
import com.whyc.pojo.db_area.KeyInf;
import com.whyc.pojo.db_area.LockInf;
import com.whyc.pojo.db_lock_ram.LockCtlLog;
import com.whyc.pojo.db_lock_ram.LockReport;
import com.whyc.pojo.db_user.UserInf;
import com.whyc.util.ActionUtil;
import com.whyc.util.PageInfoUtils;
@@ -23,6 +24,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.LogRecord;
import java.util.stream.Collectors;
@Service
@@ -51,6 +53,9 @@
    @Autowired(required = false)
    private UserInfMapper uinfMapper;
    @Autowired(required = false)
    private LockReportService reportService;
@@ -508,4 +513,99 @@
            return new Response().set(1,false,"首页统计屏柜类型");
        }
    }
    //锁的工作状态
    public Response getLockState(int uid, int urole) {
        try {
            List areaList = getAllAreaUser(uid, urole);
            QueryWrapper wrapper = new QueryWrapper();
            wrapper.in("area_id", areaList);
            wrapper.orderByAsc("num");
            List<LockInf> list = linfMapper.selectList(wrapper);
            Map<String, Object> map = new HashMap<>();
            map.put("sumLinf", 0);
            map.put("onlineNum", 0);
            map.put("offLineNum", 0);
            map.put("openNum", 0);
            map.put("closeNum", 0);
            map.put("unLoadNum", 0);
            //查看区域下所有的锁
            map.put("sumLinf", list.size());
            Map<Integer, List<LockInf>> onlinemap = list.stream().collect(Collectors.groupingBy(LockInf::getLockOnline));
            for (Integer state : onlinemap.keySet()) {
                if (state == 0) {
                    map.put("offLineNum", onlinemap.get(0).size());//离线
                }
                if (state == 1) {
                    map.put("onlineNum", onlinemap.get(1).size());//在线
                }
            }
            Map<Integer, List<LockInf>> openmap = list.stream().collect(Collectors.groupingBy(LockInf::getLockState));
            for (Integer open : openmap.keySet()) {
                if (open == 0) {
                    map.put("closeNum", openmap.get(0).size());//闭锁
                }
                if (open == 1) {
                    map.put("openNum", openmap.get(1).size());//开锁
                }
                if (open == -1) {
                    map.put("unLoadNum", openmap.get(-1).size());//未安装
                }
                map.put("allLinfs", list);
            }
                return new Response().setII(1, true, map, "锁的工作状态");
            } catch(Exception e){
                return new Response().set(1, false, "锁的工作状态");
        }
    }
    //实时开锁信息(全部)
    public Response getAllCtlLog(int userId, int urole) {
        //查看所有区域
        List areaList=getAllAreaUser(userId,urole);
        //查看区域下所有的锁
        QueryWrapper linfWrapper=new QueryWrapper();
        linfWrapper.in("area_id",areaList);
        List<LockInf> linfs=linfMapper.selectList(linfWrapper);
        if(linfs!=null&&linfs.size()>0){
            List<Integer> lockIds=linfs.stream().map(LockInf::getLockId) // 提取用户名
                    .collect(Collectors.toList()); // 转换为列表*/
            //获取锁的日志
            List<LockCtlLog> logList=ctlLogService.getAllLog(lockIds);
            return new Response().setII(1,true,logList,"实时开锁信息(全部)");
        }
        return new Response().set(1,false,"实时开锁信息(全部)");
    }
    //实时开锁信息(失败)
    public Response getErrorCtlog(int userId, int urole) {
        //查看所有区域
        List areaList=getAllAreaUser(userId,urole);
        //查看区域下所有的锁
        QueryWrapper linfWrapper=new QueryWrapper();
        linfWrapper.in("area_id",areaList);
        List<LockInf> linfs=linfMapper.selectList(linfWrapper);
        if(linfs!=null&&linfs.size()>0){
            List<Integer> lockIds=linfs.stream().map(LockInf::getLockId) // 提取用户名
                    .collect(Collectors.toList()); // 转换为列表*/
            //获取锁的日志
            List<LockCtlLog> logList=ctlLogService.getAllErrorLog(lockIds);
            return new Response().setII(1,true,logList,"实时开锁信息(失败)");
        }
        return new Response().set(1,false,"实时开锁信息(失败)");
    }
    //lock的使用频次
    public Response getReport(int userId, int urole) {
        //查看所有区域
        List areaList=getAllAreaUser(userId,urole);
        //查看区域下所有的锁
        QueryWrapper linfWrapper=new QueryWrapper();
        linfWrapper.in("area_id",areaList);
        List<LockInf> linfs=linfMapper.selectList(linfWrapper);
        if(linfs!=null&&linfs.size()>0){
            List<Integer> lockIds=linfs.stream().map(LockInf::getLockId) // 提取用户名
                    .collect(Collectors.toList()); // 转换为列表*/
            //获取锁的频次
            List<LockReport> reportList=reportService.getReport(lockIds);
            return new Response().setII(1,true,reportList,"lock的使用频次");
        }
        return new Response().set(1,false,"lock的使用频次");
    }
}
src/main/java/com/whyc/service/LockReportService.java
New file
@@ -0,0 +1,26 @@
package com.whyc.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.whyc.mapper.LockReportMapper;
import com.whyc.pojo.db_lock_ram.LockReport;
import com.whyc.util.ActionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class LockReportService {
    @Autowired(required = false)
    private LockReportMapper mapper;
    //获取锁的频次
    public List<LockReport> getReport(List<Integer> lockIds) {
        int nowYear=ActionUtil.getNowYear();
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.in("lock_id",lockIds);
        wrapper.eq("record_year",nowYear);
        List<LockReport> list=mapper.selectList(wrapper);
        return list;
    }
}
src/main/java/com/whyc/webSocket/HomeSocket.java
@@ -36,26 +36,16 @@
    private HttpSession httpSession;
    private static LockCtlLogService ctlLogService;
    private static AreaInfService ainfService;
    private static LockInfService lockInfService;
    @Autowired
    public void setLockCtlLogService(LockCtlLogService ctlLogService) {
        HomeSocket.ctlLogService = ctlLogService;
    }
    @Autowired
    public void setAreaInfServicee(AreaInfService ainfService) {
        HomeSocket.ainfService = ainfService;
    }
    @Autowired
    public void setLockInfService(LockInfService lockInfService) {
        HomeSocket.lockInfService = lockInfService;
    }
    @OnOpen
    public void onOpen(Session session, EndpointConfig config) {
@@ -65,7 +55,7 @@
    @OnMessage
    public void onMessage(Session session, String message){
       UserInf user = (UserInf) this.httpSession.getAttribute("user");
        UserInf user = (UserInf) this.httpSession.getAttribute("user");
        final int userId = user.getUid();
        final int urole = user.getUrole();
        Thread thread = new Thread() {
@@ -75,11 +65,11 @@
                    Map<String, Object> res = new HashMap<>();
                    while (!currentThread().isInterrupted()) {
                        ThreadPoolExecutor poolExecutor = ThreadPoolExecutorFactory.getPoolExecutor();
                        CountDownLatch latch = new CountDownLatch(7);
                        //分组统计前10开锁次数
                        CountDownLatch latch = new CountDownLatch(5);
                        poolExecutor.execute(() -> {
                            Response resGroupCtlCount = ainfService.getGroupCtlCount(userId,urole);
                            res.put("resGroupCtlCount", resGroupCtlCount);
                            //锁的工作状态
                            Response resLockState = ainfService.getLockState(userId,urole);
                            res.put("resLockState", resLockState);
                            latch.countDown();
                        });
                        poolExecutor.execute(() -> {
@@ -89,39 +79,25 @@
                            latch.countDown();
                        });
                        poolExecutor.execute(() -> {
                            //站点信息
                            Response resStationAnalysis = new Response();
                            res.put("resStationAnalysis", resStationAnalysis);
                            //lock的使用频次
                            Response resReport = ainfService.getReport(userId,urole);
                            res.put("resReport", resReport);
                            latch.countDown();
                        });
                        poolExecutor.execute(() -> {
                            //不同品牌同一时间品质和同品牌同时间品质
                            Response resProductQuaAnalysis = new Response();
                            res.put("resProductQuaAnalysis", resProductQuaAnalysis);
                            //实时开锁信息(失败)
                            Response resErrorCtlLog =  ainfService.getErrorCtlog(userId,urole);
                            res.put("resErrorCtlLog", resErrorCtlLog);
                            latch.countDown();
                        });
                        poolExecutor.execute(() -> {
                            //电池信息
                            Response res_battGroupInfo = new Response();
                            res.put("battGroupInfo", res_battGroupInfo);
                            latch.countDown();
                        });
                        poolExecutor.execute(() -> {
                            //电源信息
                            Response resPwrdevInfAnalysis = new Response();
                            res.put("resPwrdevInfAnalysis", resPwrdevInfAnalysis);
                            latch.countDown();
                        });
                        poolExecutor.execute(() -> {
                            //测试信息
                            Response resTestdataInfAnalysis = new Response();
                            res.put("resTestdataInfAnalysis", resTestdataInfAnalysis);
                            //实时开锁信息(全部)
                            Response resAllCtlLog = ainfService.getAllCtlLog(userId,urole);
                            res.put("resAllCtlLog", resAllCtlLog);
                            latch.countDown();
                        });
                        latch.await(10, TimeUnit.MINUTES);
                        session.getBasicRemote().sendObject(new Response().set(1, res));
                        session.getBasicRemote().sendObject(res);
                        sleep(5000);
                    }
                } catch (Exception e) {