Bladeren bron

修改周报生成规则

zyl 4 weken geleden
bovenliggende
commit
85c69ab94d

+ 8 - 5
liutongyi-admin/src/main/java/com/citygis/web/mapper/TabSystemMsgMapper.java

@@ -3,12 +3,13 @@ package com.citygis.web.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.citygis.web.domain.*;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
 /**
  * <p>
- *  Mapper 接口
+ * Mapper 接口
  * </p>
  *
  * @author citygis
@@ -17,15 +18,17 @@ import java.util.List;
 @Mapper
 public interface TabSystemMsgMapper extends BaseMapper<TabSystemMsg> {
 
-    List<TabSystemMsg> getStatistics(TabSystemMsg tabSystemMsg);
+//    List<TabSystemMsg> getStatistics(TabSystemMsg tabSystemMsg);
 
     List<TabSystemMsg> getTabSystemMsgList(TabSystemMsg tabSystemMsg);
 
-    List<TabSystemMsgReport> weekReport();
+//    List<TabSystemMsgReport> weekReport();
 
-    List<TabAccessTableMsg> getTabAccessTableMsgList();
+    List<TabAccessTableMsg> getTabAccessTableMsgList(@Param("startTime") String startTime,
+                                                     @Param("endTime") String endTime);
 
-    List<TabAccessTableMsg> getJkcloudCount();
+    List<TabAccessTableMsg> getJkcloudCount(@Param("startTime") String startTime,
+                                            @Param("endTime") String endTime);
 
     List<Exchange> getExchangeCount(String dateTime);
 

+ 5 - 5
liutongyi-admin/src/main/java/com/citygis/web/service/impl/TabSystemMsgServiceImpl.java

@@ -52,7 +52,7 @@ public class TabSystemMsgServiceImpl extends ServiceImpl<TabSystemMsgMapper, Tab
         List<TabAccessTableMsg> tabAccessTableMsg = new ArrayList<>();
 
         tabAccessTableMsg.addAll(getJkcloudCount());
-        tabAccessTableMsg.addAll(tabSystemMsgMapper.getTabAccessTableMsgList());
+        tabAccessTableMsg.addAll(tabSystemMsgMapper.getTabAccessTableMsgList(null, null));
 
         list.forEach(tabSystemMsg1 -> {
             tabAccessTableMsg.forEach(tabAccessTableMsg1 -> {
@@ -72,7 +72,7 @@ public class TabSystemMsgServiceImpl extends ServiceImpl<TabSystemMsgMapper, Tab
         List<TabAccessTableMsg> tabAccessTableMsg = new ArrayList<>();
 
         tabAccessTableMsg.addAll(getJkcloudCount());
-        tabAccessTableMsg.addAll(tabSystemMsgMapper.getTabAccessTableMsgList());
+        tabAccessTableMsg.addAll(tabSystemMsgMapper.getTabAccessTableMsgList(null, null));
 
         list.forEach(tabSystemMsg1 -> {
             tabAccessTableMsg.forEach(tabAccessTableMsg1 -> {
@@ -87,7 +87,7 @@ public class TabSystemMsgServiceImpl extends ServiceImpl<TabSystemMsgMapper, Tab
 
     public List<TabAccessTableMsg> getJkcloudCount() {
         DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SLAVE_TWO.name());
-        List<TabAccessTableMsg> jkcloudCount = tabSystemMsgMapper.getJkcloudCount();
+        List<TabAccessTableMsg> jkcloudCount = tabSystemMsgMapper.getJkcloudCount(null, null);
         DynamicDataSourceContextHolder.clearDataSourceType();
         return jkcloudCount;
     }
@@ -125,9 +125,9 @@ public class TabSystemMsgServiceImpl extends ServiceImpl<TabSystemMsgMapper, Tab
 
     @Override
     public void weekReport() {
-        List<TabSystemMsgReport> list = tabSystemMsgMapper.weekReport();
+        List<TabSystemMsg> list = tabSystemMsgMapper.getTabSystemMsgList(new TabSystemMsg());
 
-        List<TabAccessTableMsg> tabAccessTableMsg = tabSystemMsgMapper.getTabAccessTableMsgList();
+        List<TabAccessTableMsg> tabAccessTableMsg = tabSystemMsgMapper.getTabAccessTableMsgList(null, null);
 
         Map<String, Object> map = MapUtils.newHashMap();
 

+ 120 - 0
liutongyi-admin/src/main/java/com/citygis/web/service/task/WeekReportTask.java

@@ -0,0 +1,120 @@
+package com.citygis.web.service.task;
+
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.util.MapUtils;
+import com.citygis.common.annotation.DataSource;
+import com.citygis.common.enums.DataSourceType;
+import com.citygis.framework.datasource.DynamicDataSourceContextHolder;
+import com.citygis.web.domain.TabAccessTableMsg;
+import com.citygis.web.domain.TabFileInfo;
+import com.citygis.web.domain.TabSystemMsg;
+import com.citygis.web.mapper.TabSystemMsgMapper;
+import com.citygis.web.service.ITabFileInfoService;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Author: zyl
+ * @CreateTime: 2025-03-06
+ * @Description: 周报生成
+ * @Version: 1.0
+ */
+@Component("weekReportTask")
+@DataSource(DataSourceType.MASTER)
+public class WeekReportTask {
+
+    @Value("${weekReport.filepath}")
+    private String weekReportFilePath;
+
+    @Value("${weekReport.templateFilePath}")
+    private String templateFilePath;
+
+    @Resource
+    TabSystemMsgMapper tabSystemMsgMapper;
+
+    @Resource
+    ITabFileInfoService tabFileInfoService;
+
+    public void weekReport() {
+
+        // 获取当前日期
+        LocalDate today = LocalDate.now();
+
+        // 获取上周的同一日
+        LocalDate lastWeek = today.minusWeeks(1);
+
+        // 获取上周周一的日期
+        String lastMonday = lastWeek.with(DayOfWeek.MONDAY).toString();
+
+        // 获取上周周日的日期
+        String lastSunday = lastWeek.with(DayOfWeek.SUNDAY).toString();
+
+        List<TabSystemMsg> tabSystemMsgList = getTabSystemMsgList();
+
+        List<TabAccessTableMsg> count = new ArrayList<>();
+
+        count.addAll(getTabAccessTableMsgList(lastMonday, lastSunday));
+        count.addAll(getJkcloudCount(lastMonday, lastSunday));
+
+        Map<String, Object> map = MapUtils.newHashMap();
+
+        tabSystemMsgList.forEach(tabSystemMsgReport -> {
+            count.forEach(tabAccessTableMsg1 -> {
+                if (tabAccessTableMsg1.getTableName().equals(tabSystemMsgReport.getTableEnglishName())) {
+                    map.put(tabAccessTableMsg1.getTableName(), tabAccessTableMsg1.getCount());
+                }
+            });
+        });
+
+        // 设置文件保存路径
+        String filePath = weekReportFilePath + "疾控周报" + lastMonday + "-" + lastSunday + ".xlsx";
+
+        EasyExcel.write(filePath).withTemplate(templateFilePath).sheet().doFill(map);
+
+        saveTabFileInfo(filePath);
+    }
+
+    public List<TabSystemMsg> getTabSystemMsgList() {
+        DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SLAVE.name());
+        List<TabSystemMsg> list = tabSystemMsgMapper.getTabSystemMsgList(new TabSystemMsg());
+        DynamicDataSourceContextHolder.clearDataSourceType();
+        return list;
+    }
+
+    public List<TabAccessTableMsg> getTabAccessTableMsgList(String startTime, String endTime) {
+        DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SLAVE.name());
+        List<TabAccessTableMsg> tabAccessTableMsgList = tabSystemMsgMapper.getTabAccessTableMsgList(startTime, endTime);
+        DynamicDataSourceContextHolder.clearDataSourceType();
+        return tabAccessTableMsgList;
+    }
+
+
+    public List<TabAccessTableMsg> getJkcloudCount(String startTime, String endTime) {
+        DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.SLAVE_TWO.name());
+        List<TabAccessTableMsg> jkcloudCount = tabSystemMsgMapper.getJkcloudCount(startTime, endTime);
+        DynamicDataSourceContextHolder.clearDataSourceType();
+        return jkcloudCount;
+    }
+
+    private void saveTabFileInfo(String filePath) {
+        //保存到主库,手动切换数据源
+//        DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER.name());
+        TabFileInfo tabFileInfo = new TabFileInfo();
+        tabFileInfo.setFileName(filePath.substring(filePath.lastIndexOf("\\") + 1));
+        tabFileInfo.setFilePath(filePath);
+        tabFileInfo.setCreateTime(new Date());
+        tabFileInfo.setCreateBy("system");
+        tabFileInfo.setSystemType("疾控周报");
+        tabFileInfoService.save(tabFileInfo);
+//        DynamicDataSourceContextHolder.clearDataSourceType();
+    }
+
+}

+ 21 - 21
liutongyi-admin/src/main/resources/mapper/TabSystemMsgMapper.xml

@@ -2,23 +2,23 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.citygis.web.mapper.TabSystemMsgMapper">
 
-    <select id="getStatistics" resultType="com.citygis.web.domain.TabSystemMsg"
-            parameterType="com.citygis.web.domain.TabSystemMsg">
-        SELECT id, system_name, table_name, table_english_name, access_manner, update_type, status state, ps, count,
-        data_essential_id, is_del
-        FROM test.dbo.tab_system_msg
-        where is_del = 0
-        <if test="systemName != null">
-            and system_name like concat('%',#{systemName},'%')
-        </if>
-        <if test="tableEnglishName != null">
-            and table_english_name like concat('%',#{tableEnglishName},'%')
-        </if>
-        <if test="updateType != null">
-            and update_type = #{updateType}
-        </if>
+<!--    <select id="getStatistics" resultType="com.citygis.web.domain.TabSystemMsg"-->
+<!--            parameterType="com.citygis.web.domain.TabSystemMsg">-->
+<!--        SELECT id, system_name, table_name, table_english_name, access_manner, update_type, status state, ps, count,-->
+<!--        data_essential_id, is_del-->
+<!--        FROM test.dbo.tab_system_msg-->
+<!--        where is_del = 0-->
+<!--        <if test="systemName != null">-->
+<!--            and system_name like concat('%',#{systemName},'%')-->
+<!--        </if>-->
+<!--        <if test="tableEnglishName != null">-->
+<!--            and table_english_name like concat('%',#{tableEnglishName},'%')-->
+<!--        </if>-->
+<!--        <if test="updateType != null">-->
+<!--            and update_type = #{updateType}-->
+<!--        </if>-->
 
-    </select>
+<!--    </select>-->
 
     <select id="getTabSystemMsgList" resultType="com.citygis.web.domain.TabSystemMsg"
             parameterType="com.citygis.web.domain.TabSystemMsg">
@@ -38,11 +38,11 @@
 
     </select>
 
-    <select id="weekReport" resultType="com.citygis.web.domain.TabSystemMsgReport">
-        SELECT id, system_name, table_name, table_english_name,update_type
-        FROM test.dbo.tab_system_msg
-        where is_del = 0
-    </select>
+<!--    <select id="weekReport" resultType="com.citygis.web.domain.TabSystemMsgReport">-->
+<!--        SELECT id, system_name, table_name, table_english_name,update_type-->
+<!--        FROM test.dbo.tab_system_msg-->
+<!--        where is_del = 0-->
+<!--    </select>-->
 
     <select id="getTabAccessTableMsgList" resultType="com.citygis.web.domain.TabAccessTableMsg">
         SELECT id, count, tableName