suntianwu 3 lat temu
rodzic
commit
7e1ee2f892

+ 3 - 3
src/main/java/com/care/bigscreen/entity/StOrganization.java

@@ -11,7 +11,7 @@ import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 
 import java.io.Serializable;
-import java.time.LocalDateTime;
+import java.util.Date;
 
 /**
  * 机构统计表实体类
@@ -55,11 +55,11 @@ public class StOrganization implements Serializable {
 
     @ApiModelProperty(value = "创建时间")
     @TableField("CREATE_TIME")
-    private LocalDateTime createTime;
+    private Date createTime;
 
     @ApiModelProperty(value = "更新时间")
     @TableField("MODIFY_TIME")
-    private LocalDateTime modifyTime;
+    private Date modifyTime;
 
 
 }

+ 7 - 7
src/main/java/com/care/bigscreen/entity/StStation.java

@@ -9,7 +9,7 @@ import lombok.experimental.Accessors;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
-import java.time.LocalDateTime;
+import java.util.Date;
 
 /**
  * 站点统计表实体类
@@ -90,6 +90,10 @@ public class StStation implements Serializable {
     @TableField("serve_amount")
     private Long serveAmount;
 
+    @ApiModelProperty(value = "今天服务人次")
+    @TableField("serve_today_amount")
+    private Long serveTodayAmount;
+
     @ApiModelProperty(value = "设备总数")
     @TableField("device_amount")
     private Long deviceAmount;
@@ -158,10 +162,6 @@ public class StStation implements Serializable {
     @TableField("his_outdoors_call_amount")
     private Long hisOutdoorsCallAmount;
 
-    @ApiModelProperty(value = "今天服务人次")
-    @TableField("serve_today_amount")
-    private Long serveTodayAmount;
-
     @ApiModelProperty(value = "经度")
     @TableField("longitude")
     private BigDecimal longitude;
@@ -172,11 +172,11 @@ public class StStation implements Serializable {
 
     @ApiModelProperty(value = "创建时间")
     @TableField("CREATE_TIME")
-    private LocalDateTime createTime;
+    private Date createTime;
 
     @ApiModelProperty(value = "更新时间")
     @TableField("MODIFY_TIME")
-    private LocalDateTime modifyTime;
+    private Date modifyTime;
 
 
 }

+ 8 - 0
src/main/java/com/care/bigscreen/mapper/StOrganizationMapper.java

@@ -3,6 +3,10 @@ package com.care.bigscreen.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.care.bigscreen.entity.StOrganization;
 
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
 
 /**
  * 机构统计表(st_organization)表数据库访问层
@@ -11,5 +15,9 @@ import com.care.bigscreen.entity.StOrganization;
  * @since 2021-05-21 00:08:32
  */
 public interface StOrganizationMapper extends BaseMapper<StOrganization> {
+    /**
+     * 站点统计列表查询
+     */
+    List<StOrganization> selectStOrganizationList();
 
 }

+ 7 - 0
src/main/java/com/care/bigscreen/mapper/StStationMapper.java

@@ -2,6 +2,9 @@ package com.care.bigscreen.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.care.bigscreen.entity.StStation;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 
 /**
@@ -11,5 +14,9 @@ import com.care.bigscreen.entity.StStation;
  * @since 2021-05-21 00:08:32
  */
 public interface StStationMapper extends BaseMapper<StStation> {
+    /**
+     * 站点统计列表查询
+     */
+    List<StStation> selectStStationList();
 
 }

+ 8 - 17
src/main/java/com/care/bigscreen/schedule/BigScreenSchedule.java

@@ -2,17 +2,17 @@ package com.care.bigscreen.schedule;
 
 
 
-import com.care.bigscreen.mapper.StOrganizationMapper;
-import com.care.bigscreen.mapper.StStationMapper;
 
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
+
+import com.care.bigscreen.service.BigScreenService;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 
 
+
 /** 大屏统计调度
  * @author 许明
  * @version 2.7.0.0 创建于 2018/7/16
@@ -20,26 +20,17 @@ import org.springframework.scheduling.annotation.Scheduled;
 @Configuration
 @EnableScheduling
 public class BigScreenSchedule {
-    private static final Logger logger = LogManager.getLogger(BigScreenSchedule.class);
 
     @Autowired
-    private StOrganizationMapper stOrganizationMapper;
-
-    @Autowired
-    private StStationMapper stStationMapper;
+    private BigScreenService bigScreenService;
 
 
     /**
-     * 10 钟调用一次
+     * 10 钟调用一次
      */
-    @Scheduled(cron = "0/10 * * * * ?")
+    @Scheduled(cron = "* 0/10 * * * ?")
     public void exeStatistics() {
-        try {
-
-        } catch (Exception e) {
-            logger.error("统计计算出错:{}", e.getMessage());
-        }
+        bigScreenService.exeStatistics();
     }
 
-
 }

+ 5 - 0
src/main/java/com/care/bigscreen/service/BigScreenService.java

@@ -88,4 +88,9 @@ public interface BigScreenService {
      * 调用websocket推送实时事件标识给前端
      */
     void pushRtEventFlag(String stationId);
+
+    /**
+     * 进行统计
+     */
+    void exeStatistics();
 }

+ 79 - 0
src/main/java/com/care/bigscreen/service/impl/BigScreenServiceImpl.java

@@ -1,16 +1,25 @@
 package com.care.bigscreen.service.impl;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.care.bigscreen.entity.StOrganization;
+import com.care.bigscreen.entity.StStation;
 import com.care.bigscreen.mapper.BigSreenMapper;
+import com.care.bigscreen.mapper.StOrganizationMapper;
+import com.care.bigscreen.mapper.StStationMapper;
 import com.care.bigscreen.service.BigScreenService;
 import com.care.bigscreen.vo.*;
 import com.care.bigscreen.websocket.BigScreenWebSocketEndpoint;
 import com.care.common.service.CareStationService;
+import com.care.common.util.DomainEquals;
 import com.care.common.vo.PageResVO;
 import com.care.common.util.PageUtil;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.Date;
 import java.util.List;
 
 
@@ -22,11 +31,20 @@ import java.util.List;
  */
 @Service
 public class BigScreenServiceImpl implements BigScreenService {
+    private static final Logger logger = LogManager.getLogger(BigScreenServiceImpl.class);
 
     @Autowired
     private BigSreenMapper bigSreenMapper;
+
     @Autowired
     private CareStationService careStationService;
+
+    @Autowired
+    private StStationMapper stStationMapper;
+
+    @Autowired
+    private StOrganizationMapper stOrganizationMapper;
+
     /**
      * 大屏统计查询
      * @return 搜索符合条件的大屏统计数据
@@ -176,6 +194,67 @@ public class BigScreenServiceImpl implements BigScreenService {
      */
     @Override
     public void pushRtEventFlag(String stationId) {
+        //触发统计
+        exeStatistics();
         BigScreenWebSocketEndpoint.sendMsgToFront(stationId,"rt_event_happen");
     }
+
+    /**
+     * 进行统计
+     */
+    @Override
+    public void exeStatistics(){
+        try {
+            List<StStation> stStationList = stStationMapper.selectStStationList();
+            for(StStation stStation : stStationList) {
+                QueryWrapper<StStation> queryWrapper = new QueryWrapper<>();
+                //查询表中是否存在
+                queryWrapper.lambda().eq(StStation::getStationId, stStation.getStationId());
+                StStation stStationDb = stStationMapper.selectOne(queryWrapper);
+                if (stStationDb == null) { //插入
+                    Date now = new Date();
+                    stStation.setCreateTime(now);
+                    stStation.setModifyTime(now);
+                    stStationMapper.insert(stStation);
+                } else { //更新
+                    stStation.setCreateTime(stStationDb.getCreateTime());
+                    stStation.setModifyTime(stStationDb.getModifyTime());
+                    stStation.setId(stStationDb.getId());
+                    //其余属性不一样的就更新
+                    if (!DomainEquals.domainEquals(stStation,stStationDb)){
+                        Date now = new Date();
+                        stStation.setModifyTime(now);
+                        stStationMapper.updateById(stStation);
+                    }
+                }
+            }
+
+            List<StOrganization> stOrganizationList = stOrganizationMapper.selectStOrganizationList();
+            for(StOrganization stOrganization : stOrganizationList) {
+                QueryWrapper<StOrganization> queryWrapper = new QueryWrapper<>();
+                //查询表中是否存在
+                queryWrapper.lambda().eq(StOrganization::getOrgId, stOrganization.getOrgId());
+                StOrganization stOrganizationDb = stOrganizationMapper.selectOne(queryWrapper);
+                if (stOrganizationDb == null) { //插入
+                    Date now = new Date();
+                    stOrganization.setCreateTime(now);
+                    stOrganization.setModifyTime(now);
+                    stOrganizationMapper.insert(stOrganization);
+                } else { //更新
+                    stOrganization.setCreateTime(stOrganizationDb.getCreateTime());
+                    stOrganization.setModifyTime(stOrganizationDb.getModifyTime());
+                    stOrganization.setId(stOrganizationDb.getId());
+                    //其余属性不一样的就更新
+                    if (!DomainEquals.domainEquals(stOrganization,stOrganizationDb)) {
+                        Date now = new Date();
+                        stOrganization.setModifyTime(now);
+                        stOrganizationMapper.updateById(stOrganization);
+                    }
+                }
+            }
+
+        } catch (Exception e) {
+            logger.error("统计计算出错:{}", e.getMessage());
+        }
+    }
 }

+ 148 - 0
src/main/java/com/care/common/util/DomainEquals.java

@@ -0,0 +1,148 @@
+package com.care.common.util;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class DomainEquals {
+
+
+    /**
+     * 比较两个BEAN或MAP对象的值是否相等
+     * 如果是BEAN与MAP对象比较时MAP中的key值应与BEAN的属性值名称相同且字段数目要一致
+     * @param source
+     * @param target
+     * @return
+     */
+    public static boolean domainEquals(Object source, Object target) {
+        if (source == null || target == null) {
+            return false;
+        }
+        boolean rv = true;
+        if (source instanceof Map) {
+            rv = mapOfSrc(source, target, rv);
+        } else {
+            rv = classOfSrc(source, target, rv);
+        }
+
+        return rv;
+    }
+
+    /**
+     * 源目标为MAP类型时
+     * @param source
+     * @param target
+     * @param rv
+     * @return
+     */
+    private static boolean mapOfSrc(Object source, Object target, boolean rv) {
+        HashMap<String, String> map = new HashMap<String, String>();
+        map = (HashMap) source;
+        for (String key : map.keySet()) {
+            if (target instanceof Map) {
+                HashMap<String, String> tarMap = new HashMap<String, String>();
+                tarMap = (HashMap) target;
+                if(tarMap.get(key)==null){
+                    rv = false;
+                    break;
+                }
+                if (!map.get(key).equals(tarMap.get(key))) {
+                    rv = false;
+                    break;
+                }
+            } else {
+                String tarValue = getClassValue(target, key) == null ? "" : getClassValue(target, key).toString();
+                if (!tarValue.equals(map.get(key))) {
+                    rv = false;
+                    break;
+                }
+            }
+        }
+        return rv;
+    }
+
+    /**
+     * 源目标为非MAP类型时
+     * @param source
+     * @param target
+     * @param rv
+     * @return
+     */
+    private static boolean classOfSrc(Object source, Object target, boolean rv) {
+        Class<?> srcClass = source.getClass();
+        Field[] fields = srcClass.getDeclaredFields();
+        for (Field field : fields) {
+            String nameKey = field.getName();
+            if (target instanceof Map) {
+                HashMap<String, String> tarMap = new HashMap<String, String>();
+                tarMap = (HashMap) target;
+                String srcValue = getClassValue(source, nameKey) == null ? "" : getClassValue(source, nameKey)
+                        .toString();
+                if(tarMap.get(nameKey)==null){
+                    rv = false;
+                    break;
+                }
+                if (!tarMap.get(nameKey).equals(srcValue)) {
+                    rv = false;
+                    break;
+                }
+            } else {
+                String srcValue = getClassValue(source, nameKey) == null ? "" : getClassValue(source, nameKey)
+                        .toString();
+                String tarValue = getClassValue(target, nameKey) == null ? "" : getClassValue(target, nameKey)
+                        .toString();
+                if (!srcValue.equals(tarValue)) {
+                    rv = false;
+                    break;
+                }
+            }
+        }
+        return rv;
+    }
+
+    /**
+     * 根据字段名称取值
+     * @param obj
+     * @param fieldName
+     * @return
+     */
+    private static Object getClassValue(Object obj, String fieldName) {
+        if (obj == null) {
+            return null;
+        }
+        try {
+            Class beanClass = obj.getClass();
+            Method[] ms = beanClass.getMethods();
+            for (int i = 0; i < ms.length; i++) {
+                // 非get方法不取
+                if (!ms[i].getName().startsWith("get")) {
+                    continue;
+                }
+                Object objValue = null;
+                try {
+                    objValue = ms[i].invoke(obj, new Object[] {});
+                } catch (Exception e) {
+                    continue;
+                }
+                if (objValue == null) {
+                    continue;
+                }
+                if (ms[i].getName().toUpperCase().equals(fieldName.toUpperCase())
+                        || ms[i].getName().substring(3).toUpperCase().equals(fieldName.toUpperCase())) {
+                    return objValue;
+                } else if (fieldName.toUpperCase().equals("SID")
+                        && (ms[i].getName().toUpperCase().equals("ID") || ms[i].getName().substring(3).toUpperCase()
+                        .equals("ID"))) {
+                    return objValue;
+                }
+            }
+        } catch (Exception e) {
+            // logger.info("取方法出错!" + e.toString());
+        }
+        return null;
+    }
+
+
+}

+ 13 - 0
src/main/resources/mybatis/StOrganizationMapper.xml

@@ -0,0 +1,13 @@
+<?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.care.bigscreen.mapper.StOrganizationMapper">
+
+    <select id="selectStOrganizationList" resultType="com.care.bigscreen.entity.StOrganization">
+        SELECT
+        t.id orgId,
+        (select count(1) from care_sys_user a where a.org_id = t.id and a.role = 'seat') seatsAmount,
+        (select convert(sum(call_duration)/60,decimal(20,2)) from cc_traffic_billed b where b.org_id = t.id) seatsCallMinAmount
+        FROM care_organization t
+    </select>
+
+</mapper>

+ 45 - 0
src/main/resources/mybatis/StStationMapper.xml

@@ -0,0 +1,45 @@
+<?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.care.bigscreen.mapper.StStationMapper">
+
+    <select id="selectStStationList" resultType="com.care.bigscreen.entity.StStation">
+        SELECT
+        t.id stationId,
+        t.name stationName,
+        t.org_id orgId,
+        (select count(1) from care_older a where a.station_id = t.id) olderAmount,
+        (select count(1) from care_older a where a.station_id = t.id and ROUND(DATEDIFF(CURDATE(), a.birthday)/365.2422) >= 60 and ROUND(DATEDIFF(CURDATE(), a.birthday)/365.2422) &lt; 80) older6080Amount,
+        (select count(1) from care_older a where a.station_id = t.id and ROUND(DATEDIFF(CURDATE(), a.birthday)/365.2422) >= 80) older80AboveAmount,
+        (select count(1) from care_older a where a.station_id = t.id and a.live_type = '1') aloneLivingAmount,
+        (select count(1) from care_older a where a.station_id = t.id and a.live_type = '2') noAloneLivingAmount,
+        (select count(1) from care_older a where a.station_id = t.id and a.live_type = '3') concentrateLivingAmount,
+        (select count(1) from care_older a where a.station_id = t.id and a.live_type = '4') otherLivingAmount,
+        (select count(1) from care_older a where a.station_id = t.id and a.safe_level = '1') oneLevelAmount,
+        (select count(1) from care_older a where a.station_id = t.id and a.safe_level = '1') twoLevelAmount,
+        (select count(1) from care_older a where a.station_id = t.id and a.safe_level = '1') threeLevelAmount,
+        (select count(distinct chamberlain_id) from care_chamberlain_older_rel b where b.older_id in (select a.id from care_older a where a.station_id = t.id ) ) chamberlainAmount,
+        (select count(1) from care_event_order c where c.station_id = t.id ) serveAmount,
+        (select count(1) from care_event_order c where c.station_id = t.id and c.create_time >= CURDATE()) serveTodayAmount,
+        (select count(1) from care_device d where d.station_id = t.id ) deviceAmount,
+        (select count(1) from care_device d where d.station_id = t.id and d.dev_type = '1' and d.status = '1') indoorOnlineAmount,
+        (select count(1) from care_device d where d.station_id = t.id and d.dev_type = '1' and d.status = '2') indoorOfflineAmount,
+        (select count(1) from care_device d where d.station_id = t.id and d.dev_type = '2' and d.status = '1') outdoorOnlineAmount,
+        (select count(1) from care_device d where d.station_id = t.id and d.dev_type = '2' and d.status = '2') outdoorOfflineAmount,
+        (select count(1) from care_event_order c where c.station_id = t.id and c.status in ('0','1') ) rtEventAmount,
+        (select count(1) from care_event_order c where c.station_id = t.id and c.status in ('0','1') and order_type = '21') rtFallAmount,
+        (select count(1) from care_event_order c where c.station_id = t.id and c.status in ('0','1') and order_type = '22') rtStagnationAmount,
+        (select count(1) from care_event_order c where c.station_id = t.id and c.status in ('0','1') and order_type = '23') rtFallingBedAmount,
+        (select count(1) from care_event_order c where c.station_id = t.id and c.status in ('0','1') and order_type = '31') rtActiveCallAmount,
+        (select count(1) from care_event_order c where c.station_id = t.id and c.status in ('0','1') and order_type = '32') rtOutdoorsCallAmount,
+         (select count(1) from care_event_order c where c.station_id = t.id and c.status not in ('0','1')) hisEventAmount,
+        (select count(1) from care_event_order c where c.station_id = t.id  and c.status not in ('0','1') and  order_type = '21') hisFallAmount,
+        (select count(1) from care_event_order c where c.station_id = t.id  and c.status not in ('0','1') and  order_type = '22') hisStagnationAmount,
+        (select count(1) from care_event_order c where c.station_id = t.id  and c.status not in ('0','1') and  order_type = '23') hisFallingBedAmount,
+        (select count(1) from care_event_order c where c.station_id = t.id  and c.status not in ('0','1') and  order_type = '31') hisActiveCallAmount,
+        (select count(1) from care_event_order c where c.station_id = t.id  and c.status not in ('0','1') and  order_type = '32') hisOutdoorsCallAmount,
+        t.longitude,
+        t.latitude
+        FROM care_station t
+    </select>
+
+</mapper>