Explorar o código

app根据组名查询当前时间前七天的客流量数据

bihs hai 3 meses
pai
achega
cfc833efdd

+ 32 - 0
zhjq-business/src/main/java/com/zhjq/controller/ZhjqAppController.java

@@ -0,0 +1,32 @@
+package com.zhjq.controller;
+
+
+import com.zhjq.common.core.controller.BaseController;
+import com.zhjq.common.core.domain.AjaxResult;
+import com.zhjq.service.IZhjqPassengerFlowService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/app")
+public class ZhjqAppController extends BaseController {
+
+    @Autowired
+    private IZhjqPassengerFlowService zhjqPassengerFlowService;
+
+    /**
+     * app根据组名查询当前时间前七天的客流量数据
+     *
+     * @param groupId
+     * @return
+     */
+    @GetMapping(value = "/flow/selectAppStatistics")
+    public AjaxResult selectAppStatistics(@RequestParam("groupId") String groupId) {
+        return success(zhjqPassengerFlowService.selectAppStatistics(groupId));
+    }
+
+
+}

+ 15 - 0
zhjq-business/src/main/java/com/zhjq/domain/ZhjqScenery.java

@@ -61,6 +61,12 @@ public class ZhjqScenery extends BaseEntity {
     @Excel(name = "纬度")
     @Excel(name = "纬度")
     private String latitude;
     private String latitude;
 
 
+    /**
+     * 统计组编码
+     */
+    @Excel(name = "统计组编码")
+    private String groupId;
+
     public void setId(Long id) {
     public void setId(Long id) {
         this.id = id;
         this.id = id;
     }
     }
@@ -125,6 +131,14 @@ public class ZhjqScenery extends BaseEntity {
         return latitude;
         return latitude;
     }
     }
 
 
+    public String getGroupId() {
+        return groupId;
+    }
+
+    public void setGroupId(String groupId) {
+        this.groupId = groupId;
+    }
+
     @Override
     @Override
     public String toString() {
     public String toString() {
         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
         return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
@@ -140,6 +154,7 @@ public class ZhjqScenery extends BaseEntity {
                 .append("updateTime", getUpdateTime())
                 .append("updateTime", getUpdateTime())
                 .append("longitude", getLongitude())
                 .append("longitude", getLongitude())
                 .append("latitude", getLatitude())
                 .append("latitude", getLatitude())
+                .append("groupId", getGroupId())
                 .toString();
                 .toString();
     }
     }
 }
 }

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

@@ -6,6 +6,7 @@ import com.zhjq.domain.vo.ZhjqPassengerFlowVO;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Param;
 
 
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 
 
 
 
 /**
 /**
@@ -71,4 +72,11 @@ public interface ZhjqPassengerFlowMapper {
     List<ZhjqPassengerFlow> selectGroupName();
     List<ZhjqPassengerFlow> selectGroupName();
 
 
     ZhjqPassengerFlowVO selectAllStatisticsByGroupId(JSONObject jsonObject);
     ZhjqPassengerFlowVO selectAllStatisticsByGroupId(JSONObject jsonObject);
+
+    /**
+     * app根据组名查询当前时间前七天的客流量数据
+     * @param groupId
+     * @return
+     */
+    List<Map<String, Object>> selectAppStatistics(@Param("groupId") String groupId);
 }
 }

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

@@ -2,6 +2,7 @@ package com.zhjq.service;
 
 
 import com.alibaba.fastjson2.JSONObject;
 import com.alibaba.fastjson2.JSONObject;
 import com.zhjq.domain.ZhjqPassengerFlow;
 import com.zhjq.domain.ZhjqPassengerFlow;
+import org.apache.ibatis.annotations.Param;
 
 
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
@@ -65,4 +66,11 @@ public interface IZhjqPassengerFlowService {
     Map<String, Object> selectAllStatistics(JSONObject jsonObject);
     Map<String, Object> selectAllStatistics(JSONObject jsonObject);
 
 
     List<ZhjqPassengerFlow> selectGroupName();
     List<ZhjqPassengerFlow> selectGroupName();
+
+    /**
+     * app根据组名查询当前时间前七天的客流量数据
+     * @param groupId
+     * @return
+     */
+    Map<String, Object> selectAppStatistics(String groupId);
 }
 }

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

@@ -9,11 +9,12 @@ import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
+import java.util.stream.IntStream;
 
 
 
 
 /**
 /**
@@ -96,7 +97,7 @@ public class ZhjqPassengerFlowServiceImpl implements IZhjqPassengerFlowService {
     @Override
     @Override
     public Map<String, Object> selectAllStatistics(JSONObject jsonObject) {
     public Map<String, Object> selectAllStatistics(JSONObject jsonObject) {
         Map<String, Object> map = new HashMap<>();
         Map<String, Object> map = new HashMap<>();
-         if (ObjectUtils.isNotEmpty(jsonObject.get("groupId"))) {
+        if (ObjectUtils.isNotEmpty(jsonObject.get("groupId"))) {
             ZhjqPassengerFlowVO vo = zhjqPassengerFlowMapper.selectAllStatisticsByGroupId(jsonObject);
             ZhjqPassengerFlowVO vo = zhjqPassengerFlowMapper.selectAllStatisticsByGroupId(jsonObject);
             map.put("data", vo);
             map.put("data", vo);
         } else {
         } else {
@@ -123,4 +124,44 @@ public class ZhjqPassengerFlowServiceImpl implements IZhjqPassengerFlowService {
     public List<ZhjqPassengerFlow> selectGroupName() {
     public List<ZhjqPassengerFlow> selectGroupName() {
         return zhjqPassengerFlowMapper.selectGroupName();
         return zhjqPassengerFlowMapper.selectGroupName();
     }
     }
+
+    @Override
+    public Map<String, Object> selectAppStatistics(String groupId) {
+        Map<String, Object> map = new HashMap<>();
+        List<Map<String, Object>> maps = zhjqPassengerFlowMapper.selectAppStatistics(groupId);
+        List<String> last7DaysIncludingToday = getLast7DaysFormatted();
+        List<Object> inNumList = new ArrayList<>();
+        List<Object> dateList = new ArrayList<>();
+        for (String day : last7DaysIncludingToday) {
+            boolean found = false;
+            for (Map<String, Object> record : maps) {
+                String insertTime = String.valueOf(record.get("insertTime"));
+                if (day.equals(insertTime)) {
+                    inNumList.add(record.get("noRepeatInNum"));
+                    dateList.add(day);
+                    found = true;
+                    break;
+                }
+            }
+            if (!found) {
+                inNumList.add(0);
+                dateList.add(day);
+            }
+        }
+        int totalFlow = maps.stream()
+                .map(m -> Integer.parseInt(String.valueOf(m.getOrDefault("noRepeatInNum", 0))))
+                .reduce(0, Integer::sum);
+        map.put("totalFlow", totalFlow);
+        map.put("date", dateList);
+        map.put("datasource", inNumList);
+        return map;
+    }
+
+    public static List<String> getLast7DaysFormatted() {
+        LocalDate today = LocalDate.now();
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        return IntStream.rangeClosed(0, 6)
+                .mapToObj(i -> today.minusDays(6 - i).format(formatter))
+                .collect(Collectors.toList());
+    }
 }
 }

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

@@ -85,7 +85,9 @@ public class ZhjqSceneryServiceImpl implements IZhjqSceneryService {
     public int updateZhjqScenery(ZhjqScenery zhjqScenery) {
     public int updateZhjqScenery(ZhjqScenery zhjqScenery) {
         zhjqScenery.setUpdateTime(DateUtils.getNowDate());
         zhjqScenery.setUpdateTime(DateUtils.getNowDate());
         zhjqScenery.setContent(StringUtils.space2nbsp(zhjqScenery.getContent()));
         zhjqScenery.setContent(StringUtils.space2nbsp(zhjqScenery.getContent()));
-        zhjqScenery.setSceneryUrl(zhjqScenery.getSceneryUrl().replace(configService.selectConfigByKey("server_url"),""));
+        if(StringUtils.isNotEmpty(zhjqScenery.getSceneryUrl())){
+            zhjqScenery.setSceneryUrl(zhjqScenery.getSceneryUrl().replace(configService.selectConfigByKey("server_url"),""));
+        }
         return zhjqSceneryMapper.updateZhjqScenery(zhjqScenery);
         return zhjqSceneryMapper.updateZhjqScenery(zhjqScenery);
     }
     }
 
 

+ 34 - 0
zhjq-business/src/main/resources/mapper/ZhjqPassengerFlowMapper.xml

@@ -273,4 +273,38 @@
         ORDER BY insert_time desc
         ORDER BY insert_time desc
         limit 1
         limit 1
     </select>
     </select>
+
+    <select id="selectAppStatistics" resultType="java.util.Map">
+        SELECT
+            noRepeatInNum,
+            insertTime
+        FROM
+            (
+                SELECT
+                    t1.no_repeat_in_num noRepeatInNum,
+                    DATE_FORMAT( t1.insert_time, '%Y-%m-%d' ) insertTime
+                FROM
+                    zhjq_passenger_flow t1
+                WHERE
+                    t1.insert_time >= DATE_SUB( CURDATE(), INTERVAL 7 DAY )
+                  AND t1.group_id = #{groupId}
+                  AND t1.id = (
+                    SELECT
+                        t2.id
+                    FROM
+                        zhjq_passenger_flow t2
+                    WHERE
+                    DATE( t2.insert_time ) = DATE( t1.insert_time )
+			AND t2.group_name = t1.group_name
+        ORDER BY
+            t2.insert_time DESC
+            LIMIT 1
+            )
+        ORDER BY
+            insertTime DESC
+            LIMIT 7
+            ) tmp
+        ORDER BY
+            tmp.insertTime ASC;
+    </select>
 </mapper>
 </mapper>

+ 6 - 1
zhjq-business/src/main/resources/mapper/ZhjqSceneryMapper.xml

@@ -17,6 +17,7 @@
         <result property="updateTime" column="update_time"/>
         <result property="updateTime" column="update_time"/>
         <result property="longitude" column="longitude"/>
         <result property="longitude" column="longitude"/>
         <result property="latitude" column="latitude"/>
         <result property="latitude" column="latitude"/>
+        <result property="groupId" column="group_id"/>
     </resultMap>
     </resultMap>
 
 
     <sql id="selectZhjqSceneryVo">
     <sql id="selectZhjqSceneryVo">
@@ -31,7 +32,8 @@
                update_name,
                update_name,
                update_time,
                update_time,
                longitude,
                longitude,
-               latitude
+               latitude,
+               group_id
         from zhjq_scenery
         from zhjq_scenery
     </sql>
     </sql>
 
 
@@ -83,6 +85,7 @@
             <if test="updateTime != null">update_time,</if>
             <if test="updateTime != null">update_time,</if>
             <if test="longitude != null">longitude,</if>
             <if test="longitude != null">longitude,</if>
             <if test="latitude != null">latitude,</if>
             <if test="latitude != null">latitude,</if>
+            <if test="groupId != null">group_id,</if>
         </trim>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
         <trim prefix="values (" suffix=")" suffixOverrides=",">
             <if test="id != null">#{id},</if>
             <if test="id != null">#{id},</if>
@@ -97,6 +100,7 @@
             <if test="updateTime != null">#{updateTime},</if>
             <if test="updateTime != null">#{updateTime},</if>
             <if test="longitude != null">#{longitude},</if>
             <if test="longitude != null">#{longitude},</if>
             <if test="latitude != null">#{latitude},</if>
             <if test="latitude != null">#{latitude},</if>
+            <if test="groupId != null">#{groupId},</if>
         </trim>
         </trim>
     </insert>
     </insert>
 
 
@@ -114,6 +118,7 @@
             <if test="updateTime != null">update_time = #{updateTime},</if>
             <if test="updateTime != null">update_time = #{updateTime},</if>
             <if test="longitude != null">longitude = #{longitude},</if>
             <if test="longitude != null">longitude = #{longitude},</if>
             <if test="latitude != null">latitude = #{latitude},</if>
             <if test="latitude != null">latitude = #{latitude},</if>
+            <if test="groupId != null">group_id = #{groupId},</if>
         </trim>
         </trim>
         where id = #{id}
         where id = #{id}
     </update>
     </update>

+ 3 - 1
zhjq-framework/src/main/java/com/zhjq/framework/config/SecurityConfig.java

@@ -111,7 +111,9 @@ public class SecurityConfig {
                     requests.antMatchers("/login", "/register", "/captchaImage", "/appLogin").permitAll()
                     requests.antMatchers("/login", "/register", "/captchaImage", "/appLogin").permitAll()
                             // 静态资源,可匿名访问
                             // 静态资源,可匿名访问
                             .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
                             .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
-                            .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**", "/weather/**","/app/voice/app/**","/system/config/configKey/**","/system/notice/**").permitAll()
+                            .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**", "/weather/**",
+                                    "/app/voice/app/**","/system/config/configKey/**","/system/notice/**").permitAll()
+                            .antMatchers("/app/**").permitAll()
                             // 除上面外的所有请求全部需要鉴权认证
                             // 除上面外的所有请求全部需要鉴权认证
                             .anyRequest().authenticated();
                             .anyRequest().authenticated();
                 })
                 })

+ 6 - 2
zhjq-ui/src/views/system/scenery/index.vue

@@ -107,7 +107,7 @@
 
 
     <!-- 添加或修改景点管理对话框 -->
     <!-- 添加或修改景点管理对话框 -->
     <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
     <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
-      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
+      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
         <el-form-item label="景点名称" prop="sceneryName">
         <el-form-item label="景点名称" prop="sceneryName">
           <el-input v-model="form.sceneryName" placeholder="请输入景点名称" maxlength="30" show-word-limit/>
           <el-input v-model="form.sceneryName" placeholder="请输入景点名称" maxlength="30" show-word-limit/>
         </el-form-item>
         </el-form-item>
@@ -117,6 +117,9 @@
         <el-form-item label="纬度" prop="latitude">
         <el-form-item label="纬度" prop="latitude">
           <el-input v-model="form.latitude" placeholder="请输入纬度" maxlength="20" show-word-limit/>
           <el-input v-model="form.latitude" placeholder="请输入纬度" maxlength="20" show-word-limit/>
         </el-form-item>
         </el-form-item>
+        <el-form-item label="统计组编码" prop="groupId">
+          <el-input v-model="form.groupId" placeholder="请输入统计组编码" maxlength="50" show-word-limit/>
+        </el-form-item>
         <el-form-item label="图片" prop="img">
         <el-form-item label="图片" prop="img">
           <file-upload v-model="form.sceneryUrl" :limit="1" :file-type="['png','jpg','jpeg']" :file-size="10"/>
           <file-upload v-model="form.sceneryUrl" :limit="1" :file-type="['png','jpg','jpeg']" :file-size="10"/>
         </el-form-item>
         </el-form-item>
@@ -167,7 +170,8 @@ export default {
         createName: null,
         createName: null,
         updateName: null,
         updateName: null,
         longitude: null,
         longitude: null,
-        latitude: null
+        latitude: null,
+        groupId: null
       },
       },
       // 表单参数
       // 表单参数
       form: {},
       form: {},