Browse Source

实时客流量

bihuisong 3 months ago
parent
commit
d6cc5d34bf

+ 8 - 1
zhjq-business/src/main/java/com/zhjq/controller/ZhjqPassengerFlowController.java

@@ -9,6 +9,7 @@ import com.zhjq.common.utils.poi.ExcelUtil;
 import com.zhjq.domain.ZhjqPassengerFlow;
 import com.zhjq.service.IZhjqPassengerFlowService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
@@ -18,7 +19,7 @@ import java.util.List;
  * 客流量统计Controller
  *
  * @author ruoyi
- * @date 2025-02-13
+ * @date 2025-02-14
  */
 @RestController
 @RequestMapping("/system/flow")
@@ -29,6 +30,7 @@ public class ZhjqPassengerFlowController extends BaseController {
     /**
      * 查询客流量统计列表
      */
+    @PreAuthorize("@ss.hasPermi('system:flow:list')")
     @GetMapping("/list")
     public TableDataInfo list(ZhjqPassengerFlow zhjqPassengerFlow) {
         startPage();
@@ -39,6 +41,7 @@ public class ZhjqPassengerFlowController extends BaseController {
     /**
      * 导出客流量统计列表
      */
+    @PreAuthorize("@ss.hasPermi('system:flow:export')")
     @Log(title = "客流量统计", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     public void export(HttpServletResponse response, ZhjqPassengerFlow zhjqPassengerFlow) {
@@ -50,6 +53,7 @@ public class ZhjqPassengerFlowController extends BaseController {
     /**
      * 获取客流量统计详细信息
      */
+    @PreAuthorize("@ss.hasPermi('system:flow:query')")
     @GetMapping(value = "/{id}")
     public AjaxResult getInfo(@PathVariable("id") Long id) {
         return success(zhjqPassengerFlowService.selectZhjqPassengerFlowById(id));
@@ -58,6 +62,7 @@ public class ZhjqPassengerFlowController extends BaseController {
     /**
      * 新增客流量统计
      */
+    @PreAuthorize("@ss.hasPermi('system:flow:add')")
     @Log(title = "客流量统计", businessType = BusinessType.INSERT)
     @PostMapping
     public AjaxResult add(@RequestBody ZhjqPassengerFlow zhjqPassengerFlow) {
@@ -67,6 +72,7 @@ public class ZhjqPassengerFlowController extends BaseController {
     /**
      * 修改客流量统计
      */
+    @PreAuthorize("@ss.hasPermi('system:flow:edit')")
     @Log(title = "客流量统计", businessType = BusinessType.UPDATE)
     @PutMapping
     public AjaxResult edit(@RequestBody ZhjqPassengerFlow zhjqPassengerFlow) {
@@ -76,6 +82,7 @@ public class ZhjqPassengerFlowController extends BaseController {
     /**
      * 删除客流量统计
      */
+    @PreAuthorize("@ss.hasPermi('system:flow:remove')")
     @Log(title = "客流量统计", businessType = BusinessType.DELETE)
     @DeleteMapping("/{ids}")
     public AjaxResult remove(@PathVariable Long[] ids) {

+ 49 - 25
zhjq-business/src/main/java/com/zhjq/domain/ZhjqPassengerFlow.java

@@ -1,16 +1,18 @@
 package com.zhjq.domain;
 
 import com.zhjq.common.annotation.Excel;
-import com.zhjq.common.core.domain.BaseEntity;
 import lombok.Data;
 
 import java.util.Date;
 
 /**
- * 客流量统计 zhjq_passenger_flow
+ * 客流量统计对象 zhjq_passenger_flow
+ *
+ * @author ruoyi
+ * @date 2025-02-14
  */
 @Data
-public class ZhjqPassengerFlow extends BaseEntity {
+public class ZhjqPassengerFlow {
     private static final long serialVersionUID = 1L;
 
     /**
@@ -25,51 +27,73 @@ public class ZhjqPassengerFlow extends BaseEntity {
     private String groupId;
 
     /**
-     * 统计组所在区域id
+     * 统计组名称
      */
-    @Excel(name = "统计组所在区域id")
-    private String regionId;
+    @Excel(name = "统计组名称")
+    private String groupName;
 
     /**
-     * iso统计时间
+     * 进客量
      */
-    @Excel(name = "iso统计时间")
-    private Date statisticsTime;
+    @Excel(name = "进客量")
+    private Long flowInNum;
 
     /**
-     * 去重后进入人数
+     * 去重后进客量
      */
-    @Excel(name = "去重后进入人数")
-    private Integer enter;
+    @Excel(name = "去重后进客量")
+    private Long noRepeatInNum;
 
     /**
-     * 去重后离开人数
+     * 出客量
      */
-    @Excel(name = "去重后离开人数")
-    private Integer exit;
+    @Excel(name = "出客量")
+    private Long flowOutNum;
 
     /**
-     * 经过人数
+     * 去重后出客量
      */
-    @Excel(name = "经过人数")
-    private Integer pass;
+    @Excel(name = "去重后出客量")
+    private Long noRepeatOutNum;
+
+    /**
+     * 集客力
+     */
+    @Excel(name = "集客力")
+    private Long holdValue;
 
     /**
      * 保有量
      */
     @Excel(name = "保有量")
-    private Integer holdValue;
+    private String netValue;
+
+    /**
+     * 创建时间
+     */
+    private Long createTime;
+
+    /**
+     * 更新时间
+     */
+    private Long updateTime;
+
+    /**
+     * 统计时间
+     */
+    @Excel(name = "统计时间", width = 30, dateFormat = "yyyy-MM-dd")
+    private Date statTime;
 
     /**
-     * 去重前进入人数
+     * 过店人数
      */
-    @Excel(name = "去重前进入人数")
-    private Integer allEnter;
+    @Excel(name = "过店人数")
+    private Long passShopNumber;
 
     /**
-     * 去重前离开人数
+     * 插入时间
      */
-    @Excel(name = "去重前离开人数")
-    private Integer allExit;
+    @Excel(name = "插入时间", width = 30, dateFormat = "yyyy-MM-dd")
+    private Date insertTime;
 
 }

+ 2 - 2
zhjq-business/src/main/java/com/zhjq/mapper/ZhjqPassengerFlowMapper.java

@@ -10,7 +10,7 @@ import java.util.List;
  * 客流量统计Mapper接口
  *
  * @author ruoyi
- * @date 2025-02-13
+ * @date 2025-02-14
  */
 public interface ZhjqPassengerFlowMapper {
     /**
@@ -62,5 +62,5 @@ public interface ZhjqPassengerFlowMapper {
     public int deleteZhjqPassengerFlowByIds(Long[] ids);
 
 
-    int insertBatch(@Param("list") List<ZhjqPassengerFlow> list);
+    void insertBatch(@Param("list") List<ZhjqPassengerFlow> list);
 }

+ 1 - 1
zhjq-business/src/main/java/com/zhjq/service/IZhjqPassengerFlowService.java

@@ -9,7 +9,7 @@ import java.util.List;
  * 客流量统计Service接口
  *
  * @author ruoyi
- * @date 2025-02-13
+ * @date 2025-02-14
  */
 public interface IZhjqPassengerFlowService {
     /**

+ 1 - 1
zhjq-business/src/main/java/com/zhjq/service/imp/ZhjqPassengerFlowServiceImpl.java

@@ -13,7 +13,7 @@ import java.util.List;
  * 客流量统计Service业务层处理
  *
  * @author ruoyi
- * @date 2025-02-13
+ * @date 2025-02-14
  */
 @Service
 public class ZhjqPassengerFlowServiceImpl implements IZhjqPassengerFlowService {

+ 33 - 13
zhjq-business/src/main/java/com/zhjq/utils/PersonCountGroupURL.java

@@ -1,7 +1,6 @@
 package com.zhjq.utils;
 
 
-import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONObject;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.type.TypeReference;
@@ -13,10 +12,8 @@ import com.zhjq.domain.ZhjqPassengerFlow;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 /**
  * 获取监控点预览取流URLv2
@@ -47,21 +44,21 @@ public class PersonCountGroupURL {
         jsonBody.put("expand", "streamform=ps");
         String body = jsonBody.toJSONString();
         JSONObject json = JSONObject.parseObject(ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null));// post请求application/json类型参数
-        List<String> groupIds = new ArrayList<>();
+        StringBuilder groupIds = new StringBuilder();
         if (json.get("code").equals("0")) {
             List<Map<String, String>> list = (List<Map<String, String>>) JSONObject.parseObject(json.get("data").toString()).get("list");
             if (!CollectionUtils.isEmpty(list)) {
                 for (Map<String, String> map : list) {
-                    groupIds.add(map.get("groupId"));
+                    groupIds.append(map.get("groupId")).append(",");
                 }
             }
         }
-        JSONObject jsonObject = PassengerURL(host, appKey, appSecret, groupIds);
+        JSONObject jsonObject = PassengerURL(host, appKey, appSecret, groupIds.substring(0, groupIds.length() - 1));
         if (jsonObject.get("code").equals("0")) {
             ObjectMapper objectMapper = new ObjectMapper();
             objectMapper.registerModule(new JavaTimeModule()); // 注册时间模块
             try {
-                returnList = objectMapper.readValue(jsonObject.get("data").toString(), new TypeReference<List<ZhjqPassengerFlow>>() {});
+                returnList = objectMapper.readValue(JSONObject.parseObject(jsonObject.get("data").toString()).get("list").toString(), new TypeReference<List<ZhjqPassengerFlow>>() {});
             } catch (JsonProcessingException e) {
                 throw new RuntimeException(e);
             }
@@ -70,25 +67,48 @@ public class PersonCountGroupURL {
     }
 
 
-    public static JSONObject PassengerURL(String host, String appKey, String appSecret, List<String> groupIds) {
+    public static JSONObject PassengerURL(String host, String appKey, String appSecret, String groupIds) {
 
         ArtemisConfig.host = host; // 平台的ip端口
         ArtemisConfig.appKey = appKey;  // 密钥appkey
         ArtemisConfig.appSecret = appSecret;// 密钥appSecret
         final String ARTEMIS_PATH = "/artemis";
-        final String previewURLsApi = ARTEMIS_PATH + "/api/cfas/v3/passenger/realTime";
+        final String previewURLsApi = ARTEMIS_PATH + "/api/cfas/v2/passengerFlow/groups";
         Map<String, String> path = new HashMap<String, String>(2) {
             {
                 put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
             }
         };
+
+        String[] timeStr = extracted();
+
         String contentType = "application/json";
-        String jsonString = JSON.toJSONString(groupIds);
-        JSONObject json = JSONObject.parseObject(ArtemisHttpUtil.doPostStringArtemis(path, jsonString, null, null, contentType, null));// post请求application/json类型参数
+        JSONObject jsonBody = new JSONObject();
+        jsonBody.put("ids", groupIds);
+        jsonBody.put("granularity", "hourly");
+        jsonBody.put("startTime", timeStr[0]);
+        jsonBody.put("endTime", timeStr[1]);
+        String body = jsonBody.toJSONString();
+        JSONObject json = JSONObject.parseObject(ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null));// post请求application/json类型参数
 
         return json;
     }
 
+    private static String[] extracted() {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
+        Date date = new Date();
+        // 创建 Calendar 实例并设置为当前时间
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        // 减去 5 分钟
+        calendar.add(Calendar.MINUTE, -5);
+        // 获取前 5 分钟的时间
+        Date newDate = calendar.getTime();
+        String endTime = sdf.format(date);
+        String startTime = sdf.format(newDate);
+        return new String[]{startTime, endTime};
+    }
+
 
     public static void main(String[] args) {
         List<ZhjqPassengerFlow> result = PersonCountGroupURL("218.62.80.146:1443", "28356728", "C3K889wQUgVlSj1BMay6");

+ 115 - 60
zhjq-business/src/main/resources/mapper/ZhjqPassengerFlowMapper.xml

@@ -7,27 +7,35 @@
     <resultMap type="ZhjqPassengerFlow" id="ZhjqPassengerFlowResult">
         <result property="id" column="id"/>
         <result property="groupId" column="group_id"/>
-        <result property="regionId" column="region_id"/>
-        <result property="statisticsTime" column="statistics_time"/>
-        <result property="enter" column="enter"/>
-        <result property="exit" column="exit"/>
-        <result property="pass" column="pass"/>
+        <result property="groupName" column="group_name"/>
+        <result property="flowInNum" column="flow_in_num"/>
+        <result property="noRepeatInNum" column="no_repeat_in_num"/>
+        <result property="flowOutNum" column="flow_out_num"/>
+        <result property="noRepeatOutNum" column="no_repeat_out_num"/>
         <result property="holdValue" column="hold_value"/>
-        <result property="allEnter" column="all_enter"/>
-        <result property="allExit" column="all_exit"/>
+        <result property="createTime" column="create_time"/>
+        <result property="updateTime" column="update_time"/>
+        <result property="netValue" column="net_value"/>
+        <result property="statTime" column="start_time"/>
+        <result property="passShopNumber" column="pass_shop_number"/>
+        <result property="insertTime" column="insert_time"/>
     </resultMap>
 
     <sql id="selectZhjqPassengerFlowVo">
         select id,
                group_id,
-               region_id,
-               statistics_time,
-               enter,
-               exit,
-               pass,
+               group_name,
+               flow_in_num,
+               no_repeat_in_num,
+               flow_out_num,
+               no_repeat_out_num,
                hold_value,
-               all_enter,
-               all_exit
+               create_time,
+               update_time,
+               net_value,
+               start_time,
+               pass_shop_number,
+               insert_time
         from zhjq_passenger_flow
     </sql>
 
@@ -37,29 +45,32 @@
             <if test="groupId != null  and groupId != ''">
                 and group_id = #{groupId}
             </if>
-            <if test="regionId != null  and regionId != ''">
-                and region_id = #{regionId}
+            <if test="groupName != null  and groupName != ''">
+                and group_name like concat('%', #{groupName}, '%')
             </if>
-            <if test="statisticsTime != null ">
-                and statistics_time = #{statisticsTime}
+            <if test="flowInNum != null ">
+                and flow_in_num = #{flowInNum}
             </if>
-            <if test="enter != null ">
-                and enter = #{enter}
+            <if test="noRepeatInNum != null ">
+                and no_repeat_in_num = #{noRepeatInNum}
             </if>
-            <if test="exit != null ">
-                and exit = #{exit}
+            <if test="flowOutNum != null ">
+                and flow_out_num = #{flowOutNum}
             </if>
-            <if test="pass != null ">
-                and pass = #{pass}
+            <if test="noRepeatOutNum != null ">
+                and no_repeat_out_num = #{noRepeatOutNum}
             </if>
             <if test="holdValue != null ">
                 and hold_value = #{holdValue}
             </if>
-            <if test="allEnter != null ">
-                and all_enter = #{allEnter}
+            <if test="netValue != null  and netValue != ''">
+                and net_value = #{netValue}
             </if>
-            <if test="allExit != null ">
-                and all_exit = #{allExit}
+            <if test="statTime != null ">
+                and start_time = #{statTime}
+            </if>
+            <if test="passShopNumber != null ">
+                and pass_shop_number = #{passShopNumber}
             </if>
         </where>
     </select>
@@ -76,41 +87,53 @@
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="groupId != null">group_id,
             </if>
-            <if test="regionId != null">region_id,
+            <if test="groupName != null">group_name,
             </if>
-            <if test="statisticsTime != null">statistics_time,
+            <if test="flowInNum != null">flow_in_num,
             </if>
-            <if test="enter != null">enter,
+            <if test="noRepeatInNum != null">no_repeat_in_num,
             </if>
-            <if test="exit != null">exit,
+            <if test="flowOutNum != null">flow_out_num,
             </if>
-            <if test="pass != null">pass,
+            <if test="noRepeatOutNum != null">no_repeat_out_num,
             </if>
             <if test="holdValue != null">hold_value,
             </if>
-            <if test="allEnter != null">all_enter,
+            <if test="createTime != null">create_time,
+            </if>
+            <if test="updateTime != null">update_time,
+            </if>
+            <if test="netValue != null">net_value,
             </if>
-            <if test="allExit != null">all_exit,
+            <if test="statTime != null">start_time,
+            </if>
+            <if test="passShopNumber != null">pass_shop_number,
             </if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="groupId != null">#{groupId},
             </if>
-            <if test="regionId != null">#{regionId},
+            <if test="groupName != null">#{groupName},
             </if>
-            <if test="statisticsTime != null">#{statisticsTime},
+            <if test="flowInNum != null">#{flowInNum},
             </if>
-            <if test="enter != null">#{enter},
+            <if test="noRepeatInNum != null">#{noRepeatInNum},
             </if>
-            <if test="exit != null">#{exit},
+            <if test="flowOutNum != null">#{flowOutNum},
             </if>
-            <if test="pass != null">#{pass},
+            <if test="noRepeatOutNum != null">#{noRepeatOutNum},
             </if>
             <if test="holdValue != null">#{holdValue},
             </if>
-            <if test="allEnter != null">#{allEnter},
+            <if test="createTime != null">#{createTime},
+            </if>
+            <if test="updateTime != null">#{updateTime},
+            </if>
+            <if test="netValue != null">#{netValue},
             </if>
-            <if test="allExit != null">#{allExit},
+            <if test="statTime != null">#{statTime},
+            </if>
+            <if test="passShopNumber != null">#{passShopNumber},
             </if>
         </trim>
     </insert>
@@ -121,29 +144,38 @@
             <if test="groupId != null">group_id =
                 #{groupId},
             </if>
-            <if test="regionId != null">region_id =
-                #{regionId},
+            <if test="groupName != null">group_name =
+                #{groupName},
             </if>
-            <if test="statisticsTime != null">statistics_time =
-                #{statisticsTime},
+            <if test="flowInNum != null">flow_in_num =
+                #{flowInNum},
             </if>
-            <if test="enter != null">enter =
-                #{enter},
+            <if test="noRepeatInNum != null">no_repeat_in_num =
+                #{noRepeatInNum},
             </if>
-            <if test="exit != null">exit =
-                #{exit},
+            <if test="flowOutNum != null">flow_out_num =
+                #{flowOutNum},
             </if>
-            <if test="pass != null">pass =
-                #{pass},
+            <if test="noRepeatOutNum != null">no_repeat_out_num =
+                #{noRepeatOutNum},
             </if>
             <if test="holdValue != null">hold_value =
                 #{holdValue},
             </if>
-            <if test="allEnter != null">all_enter =
-                #{allEnter},
+            <if test="createTime != null">create_time =
+                #{createTime},
+            </if>
+            <if test="updateTime != null">update_time =
+                #{updateTime},
+            </if>
+            <if test="netValue != null">net_value =
+                #{netValue},
             </if>
-            <if test="allExit != null">all_exit =
-                #{allExit},
+            <if test="statTime != null">start_time =
+                #{statTime},
+            </if>
+            <if test="passShopNumber != null">pass_shop_number =
+                #{passShopNumber},
             </if>
         </trim>
         where id = #{id}
@@ -161,11 +193,34 @@
             #{id}
         </foreach>
     </delete>
-
     <insert id="insertBatch" parameterType="java.lang.Integer">
-        insert into zhjq_passenger_flow (group_id, region_id, statistics_time, enter, `exit`, pass, hold_value, all_enter, all_exit) values
-        <foreach collection="list" item="item" separator="," index="index">
-            (#{item.groupId}, #{item.regionId}, #{item.statisticsTime}, #{item.enter}, #{item.exit}, #{item.pass}, #{item.holdValue}, #{item.allEnter}, #{item.allExit})
+        insert into zhjq_passenger_flow (group_id,
+        group_name,
+        flow_in_num,
+        no_repeat_in_num,
+        flow_out_num,
+        no_repeat_out_num,
+        hold_value,
+        create_time,
+        update_time,
+        net_value,
+        stat_time,
+        pass_shop_number,
+        insert_time) values
+        <foreach item="item" collection="list" separator=",">
+            (#{item.groupId},
+            #{item.groupName},
+            #{item.flowInNum},
+            #{item.noRepeatInNum},
+            #{item.flowOutNum},
+            #{item.noRepeatOutNum},
+            #{item.holdValue},
+            #{item.createTime},
+            #{item.updateTime},
+            #{item.netValue},
+            #{item.statTime},
+            #{item.passShopNumber},
+             now())
         </foreach>
     </insert>
 </mapper>