Эх сурвалжийг харах

添加全景通每日事项数据

zhao 5 сар өмнө
parent
commit
18dee1a21e

+ 20 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/controller/SolveAffairsController.java

@@ -0,0 +1,20 @@
+package com.example.nngkxxdp.controller;
+
+import com.example.nngkxxdp.service.SolveAffairsService;
+import com.example.nngkxxdp.util.BaseResult;
+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.RestController;
+
+@RestController
+@RequestMapping("/solveAffairs")
+public class SolveAffairsController {
+    @Autowired
+    private SolveAffairsService solveAffairsService;
+
+    @GetMapping
+    public BaseResult findAll(){
+        return BaseResult.ok(solveAffairsService.findAll());
+    }
+}

+ 31 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/dao/SolveAffairsDao.java

@@ -0,0 +1,31 @@
+package com.example.nngkxxdp.dao;
+
+import com.example.nngkxxdp.entity.SolveAffairs;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+* @author zhao
+* @description 针对表【t_solve_affairs】的数据库操作Mapper
+* @createDate 2024-10-28 13:59:58
+* @Entity com.example.nngkxxdp.entity.SolveAffairs
+*/
+public interface SolveAffairsDao {
+
+    List<Integer> findAll();
+
+    void updateHandle(SolveAffairs solveAffairs);
+    void insert(SolveAffairs solveAffairs);
+    void update(SolveAffairs solveAffairs);
+
+    SolveAffairs findByDateAndType(Date date, Integer handleType);
+
+
+
+    SolveAffairs findByMonthAndType(int month, Integer handleType);
+}
+
+
+
+

+ 30 - 4
nngkxxdp/src/main/java/com/example/nngkxxdp/entity/SolveAffairs.java

@@ -2,13 +2,39 @@ package com.example.nngkxxdp.entity;
 
 import lombok.Data;
 
+import java.io.Serializable;
 import java.util.Date;
 
+/**
+ * 
+ * @TableName t_solve_affairs
+ */
 @Data
-public class SolveAffairs {
-    private Long affairdId;
+public class SolveAffairs implements Serializable {
+    /**
+     * 累计办理事项表id
+     */
+    private Integer affairdId;
+
+    /**
+     * 办理数量
+     */
     private Integer handleNum;
-    //1.本日办理数量  2.本周办理数量 3.本月办理数量 4.本年办理数量
+
+    /**
+     * 1.本日办理数量  2.本周办理数量 3.本月办理数量 4.本年办理数量
+     */
     private Integer handleType;
+
+    /**
+     * 修改时间
+     */
+    private Date updateTime;
+
+    /**
+     * 创建时间
+     */
     private Date createTime;
-}
+
+    private static final long serialVersionUID = 1L;
+}

+ 13 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/service/SolveAffairsService.java

@@ -0,0 +1,13 @@
+package com.example.nngkxxdp.service;
+
+import java.util.List;
+
+/**
+* @author zhao
+* @description 针对表【t_solve_affairs】的数据库操作Service
+* @createDate 2024-10-28 13:59:58
+*/
+public interface SolveAffairsService {
+
+    public List<Integer> findAll();
+}

+ 3 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/service/impl/SellBuildServiceImpl.java

@@ -48,16 +48,19 @@ public class SellBuildServiceImpl implements SellBuildService{
         String[] complementIds  = byId.getComplement().split(",");
         HashSet<Object> complementDetails = new HashSet<>();
         ArrayList<Object> complements = new ArrayList<>();
+        List<ComplementDetails> ComplementDetails = new ArrayList<>();
         for (String complementId : complementIds ) {
             Long complementDetailId = Long.valueOf(complementId.trim());
             complements.add(complementDetailId);
             ComplementDetails complement = complementDetailsDao.findById(complementDetailId);
             String typeName = complement.getTypeName();
+            ComplementDetails.add(complement);
             complementDetails.add(typeName);
         }
         map.put("sellBuild", byId);
         map.put("typeName",complementDetails);
         map.put("complement",complements);
+        map.put("complementDetails", ComplementDetails);
         return map;
     }
 

+ 29 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/service/impl/SolveAffairsServiceImpl.java

@@ -0,0 +1,29 @@
+package com.example.nngkxxdp.service.impl;
+
+import com.example.nngkxxdp.dao.SolveAffairsDao;
+import com.example.nngkxxdp.service.SolveAffairsService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+* @author zhao
+* @description 针对表【t_solve_affairs】的数据库操作Service实现
+* @createDate 2024-10-28 13:59:58
+*/
+@Service
+public class SolveAffairsServiceImpl implements SolveAffairsService{
+    @Autowired
+    private SolveAffairsDao solveAffairsDao;
+
+
+    @Override
+    public List<Integer> findAll() {
+        return solveAffairsDao.findAll();
+    }
+}
+
+
+
+

+ 287 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/task/HandleTask.java

@@ -0,0 +1,287 @@
+package com.example.nngkxxdp.task;
+
+import com.example.nngkxxdp.dao.SolveAffairsDao;
+import com.example.nngkxxdp.entity.SolveAffairs;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.time.temporal.WeekFields;
+import java.util.Date;
+import java.util.Locale;
+import java.util.concurrent.atomic.AtomicInteger;
+
+@Service
+public class HandleTask {
+    @Autowired
+    private SolveAffairsDao solveAffairsDao;
+
+    private AtomicInteger dailyCount = new AtomicInteger(0);
+    private AtomicInteger weeklyCount = new AtomicInteger(0);
+    private AtomicInteger monthlyCount = new AtomicInteger(0);
+
+    // 应用启动时加载今日的办件量
+    public void loadDailyCount() {
+        // 获取当前日期
+        LocalDate today = LocalDate.now();
+        // 将 LocalDate 转换为 Date
+        Date todayDate = Date.from(today.atStartOfDay(ZoneId.systemDefault()).toInstant());
+
+        // 查询数据库中是否存在当天的数据
+        SolveAffairs existing = solveAffairsDao.findByDateAndType(todayDate, 1);
+        if (existing != null) {
+            // 如果存在,则设置 dailyCount
+            dailyCount.set(existing.getHandleNum());
+        } else {
+            // 如果不存在,则设置 dailyCount 为 0
+            dailyCount.set(0);
+        }
+        System.out.println("Loaded daily count: " + dailyCount.get());
+        // 加载本周和本月的办件量
+        loadWeeklyCount();
+        loadMonthlyCount();
+    }
+
+
+    // 在每月初重置月办理数量
+    @Scheduled(cron = "0 0 0 1 * ?") // 每月1日凌晨0点执行
+    public void resetMonthlyCount() {
+        monthlyCount.set(0);
+        LocalDate today = LocalDate.now();
+        saveMonthlyCount(today, 0); // 保存本月的办件量为0
+        System.out.println("Monthly count has been reset to 0.");
+    }
+
+    @Scheduled(cron = "0 0 0 * * MON") // 每周一凌晨0点执行
+    public void resetWeeklyCount() {
+        weeklyCount.set(0);
+        LocalDate today = LocalDate.now();
+        saveWeeklyCount(today, 0); // 保存本周的办件量为0
+        System.out.println("Weekly count has been reset to 0.");
+    }
+
+    @Scheduled(cron = "0 0 0 * * ?") // 每天凌晨0点执行
+    public void resetDailyCount() {
+        // 更新本周和本月的办件量
+        updateWeeklyCount(dailyCount.get());
+        updateMonthlyCount(weeklyCount.get());
+
+        dailyCount.set(0);
+        LocalDate today = LocalDate.now();
+        saveDailyCount(today, 0);
+        System.out.println("Daily count has been reset to 0.");
+    }
+
+    @Scheduled(cron = "0 0/10 * * * ?") // 每10分钟执行
+    public void updateWorkPieceCount() {
+        LocalDateTime now = LocalDateTime.now();
+        int hour = now.getHour();
+        int minute = now.getMinute();
+        int dayOfWeek = now.getDayOfWeek().getValue(); // 1 (Monday) to 7 (Sunday)
+
+        if (dayOfWeek == 7) { // 周日
+            dailyCount.set(0); // 周日的本日办件数量设置为0
+            System.out.println("Today is Sunday, daily count set to 0.");
+        } else if (dayOfWeek >= 1 && dayOfWeek <= 5) { // 周一到周五
+            if (hour >= 9 && hour < 17) { // 办公时间
+                if (minute % 10 == 0) { // 每5分钟更新
+                    int additionalCount = calculateAdditionalCount(hour, minute);
+                    dailyCount.addAndGet(additionalCount);
+                    System.out.printf("Time: %s, Additional Count: %d, Daily Count: %d%n", now, additionalCount, dailyCount.get());
+                }
+            } else if (hour == 17 && minute < 30) { // 17:00 - 17:30
+                if (minute % 10 == 0) {
+                    int additionalCount = calculateAdditionalCount(hour, minute);
+                    dailyCount.addAndGet(additionalCount);
+                    System.out.printf("Time: %s, Additional Count: %d, Daily Count: %d%n", now, additionalCount, dailyCount.get());
+                }
+            }
+        } else if (dayOfWeek == 6) { // 周六
+            if (hour >= 9 && hour < 12) { // 办公时间
+                if (minute % 10 == 0) { // 每5分钟更新
+                    int additionalCount = calculateAdditionalCountForSaturday(hour, minute);
+                    dailyCount.addAndGet(additionalCount);
+                    System.out.printf("Time: %s, Additional Count: %d, Daily Count: %d%n", now, additionalCount, dailyCount.get());
+                }
+            }
+        }
+
+        LocalDate today = LocalDate.now();
+        saveDailyCount(today, dailyCount.get());
+
+        // 更新本周和本月的办件量
+//        updateWeeklyCount(dailyCount.get());
+//        updateMonthlyCount(weeklyCount.get());
+    }
+
+    private int calculateAdditionalCount(int hour, int minute) {
+        // 计算每10分钟的次数
+        //int n = (minute - 10) / 10;
+        switch (hour) {
+            case 9:
+                return 7; // 9点10分开始,每10分钟增加7
+            case 10:
+                return 16; // 10点10分开始,每10分钟增加17
+            case 11:
+                return 17; // 11点10分开始,每10分钟增加17
+            case 12:
+                return 3 ; // 12点开始,每10分钟增加3
+            case 13:
+                return minute == 30 ? 3 : 0; // 13点半增加3
+            case 14:
+                return 6 ; // 14点10分开始,每10分钟增加7
+            case 15:
+                return 18; // 15点10分开始,每10分钟增加18
+            case 16:
+                return 5; // 16点10分开始,每10分钟增加5
+            case 17:
+                if (minute < 30) {
+                    return 6 ; // 17点10分开始,每10分钟增加6
+                }
+                return 0; // 17点半后不再增加
+            default:
+                return 0;
+        }
+    }
+
+    private int calculateAdditionalCountForSaturday(int hour, int minute) {
+       // int n = (minute - 10) / 10;
+        switch (hour) {
+            case 9:
+                return 2 ;
+            case 10:
+                return 3 ;
+            case 11:
+                return 4 ;
+            default:
+                return 0;
+        }
+    }
+
+
+
+    private void saveDailyCount(LocalDate date, int count) {
+        SolveAffairs solveAffairs = new SolveAffairs();
+        solveAffairs.setHandleNum(count);
+        solveAffairs.setHandleType(1); // 本日办理数量
+        solveAffairs.setCreateTime(Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant()));
+        updateOrCreate(solveAffairs);
+    }
+
+    private void updateOrCreate(SolveAffairs solveAffairs) {
+        SolveAffairs existing = solveAffairsDao.findByDateAndType(solveAffairs.getCreateTime(), solveAffairs.getHandleType());
+        if (existing != null) {
+            existing.setHandleNum(solveAffairs.getHandleNum());
+            existing.setUpdateTime(new Date());
+            solveAffairsDao.update(existing);
+        } else {
+            solveAffairsDao.insert(solveAffairs);
+        }
+    }
+
+    private void loadWeeklyCount() {
+        // 获取当前日期
+        LocalDate today = LocalDate.now();
+        // 获取本周一的日期
+        LocalDate mondayOfThisWeek = today.with(WeekFields.of(Locale.getDefault()).dayOfWeek(), 1);
+        // 将 LocalDate 转换为 ZonedDateTime 再转换为 Instant
+        Date mondayDate = Date.from(mondayOfThisWeek.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
+        SolveAffairs existing = solveAffairsDao.findByDateAndType(mondayDate, 2);
+        if (existing != null) {
+            weeklyCount.set(existing.getHandleNum());
+        } else {
+            weeklyCount.set(0);
+        }
+        System.out.println("Loaded weekly count: " + weeklyCount.get());
+    }
+
+    private void loadMonthlyCount() {
+        LocalDate today = LocalDate.now();
+        int month = today.getMonthValue();
+        SolveAffairs existing = solveAffairsDao.findByMonthAndType(month, 3);
+        if (existing != null) {
+            monthlyCount.set(existing.getHandleNum());
+        } else {
+            monthlyCount.set(0);
+        }
+        System.out.println("Loaded monthly count: " + monthlyCount.get());
+    }
+
+    private void updateWeeklyCount(int dailyCount) {
+        weeklyCount.addAndGet(dailyCount);
+        saveWeeklyCount(LocalDate.now(), weeklyCount.get()); // 每次更新都保存到数据库
+
+        // 更新本月累计办件量
+        updateMonthlyCount(dailyCount);
+    }
+
+//    private void SaveWeeklyCountIfEndOfWeek() {
+//        LocalDate today = LocalDate.now();
+//        if (today.getDayOfWeek().getValue() == 7) { // 周日
+//            saveWeeklyCount(today, weeklyCount.get());
+//            weeklyCount.set(0); // 重置周计数
+//        }
+//    }
+
+    private void saveWeeklyCount(LocalDate date, int count) {
+        SolveAffairs solveAffairs = new SolveAffairs();
+        solveAffairs.setHandleNum(count);
+        solveAffairs.setHandleType(2); // 本周办理数量
+        // 获取本周一的日期
+        LocalDate mondayOfThisWeek = date.with(WeekFields.of(Locale.getDefault()).dayOfWeek(), 1);
+        // 将 LocalDate 转换为 ZonedDateTime 再转换为 Instant
+        ZonedDateTime zonedDateTime = mondayOfThisWeek.atStartOfDay(ZoneId.systemDefault());
+        Date createTime = Date.from(zonedDateTime.toInstant());
+        solveAffairs.setCreateTime(createTime);
+        updateOrCreateWeekly(solveAffairs);
+    }
+
+    private void updateOrCreateWeekly(SolveAffairs solveAffairs) {
+        SolveAffairs existing = solveAffairsDao.findByDateAndType(solveAffairs.getCreateTime(), 2);
+        if (existing != null) {
+            existing.setHandleNum(solveAffairs.getHandleNum());
+            existing.setUpdateTime(new Date()); // 更新时间为当前时间
+            solveAffairsDao.update(existing);
+        } else {
+            solveAffairsDao.insert(solveAffairs);
+        }
+    }
+
+    private void updateMonthlyCount(int dailyCount) {
+        monthlyCount.addAndGet(dailyCount);
+        saveMonthlyCount(LocalDate.now(), monthlyCount.get()); // 每次更新都保存到数据库
+    }
+
+//    private void SaveMonthlyCountIfEndOfMonth() {
+//        LocalDate today = LocalDate.now();
+//        if (today.plusDays(1).getMonthValue() != today.getMonthValue()) { // 下一天是下个月
+//            saveMonthlyCount(today, monthlyCount.get());
+//            monthlyCount.set(0); // 重置月计数
+//        }
+//    }
+
+    private void saveMonthlyCount(LocalDate date, int count) {
+        SolveAffairs solveAffairs = new SolveAffairs();
+        solveAffairs.setHandleNum(count);
+        solveAffairs.setHandleType(3); // 本月办理数量
+        solveAffairs.setCreateTime(new Date()); // 设置为当前时间
+        updateOrCreateMonthly(solveAffairs);
+    }
+
+    private void updateOrCreateMonthly(SolveAffairs solveAffairs) {
+        int month = LocalDate.now().getMonthValue();
+        SolveAffairs existing = solveAffairsDao.findByMonthAndType(month, 3);
+        if (existing != null) {
+            existing.setHandleNum(solveAffairs.getHandleNum());
+            existing.setUpdateTime(new Date()); // 更新时间为当前时间
+            solveAffairsDao.update(existing);
+        } else {
+            solveAffairs.setCreateTime(new Date()); // 设置创建时间为当前时间
+            solveAffairsDao.insert(solveAffairs);
+        }
+    }
+}

+ 55 - 0
nngkxxdp/src/main/resources/mapper/SolveAffairsDao.xml

@@ -0,0 +1,55 @@
+<?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.example.nngkxxdp.dao.SolveAffairsDao">
+
+    <resultMap id="BaseResultMap" type="com.example.nngkxxdp.entity.SolveAffairs">
+            <id property="affairdId" column="affaird_id" jdbcType="INTEGER"/>
+            <result property="handleNum" column="handle_num" jdbcType="INTEGER"/>
+            <result property="handleType" column="handle_type" jdbcType="INTEGER"/>
+            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
+            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        affaird_id,handle_num,handle_type,
+        update_time,create_time
+    </sql>
+    <insert id="insert">
+        insert into t_solve_affairs(handle_num,handle_type,create_time)
+        values(#{handleNum},#{handleType},#{createTime})
+    </insert>
+    <update id="updateHandle">
+        update t_solve_affairs
+        <set>
+            <if test="handleNum != null">
+                handle_num = #{handleNum},
+            </if>
+            <if test="handleType != null">
+                handle_type = #{handleType},
+            </if>
+        </set>
+        where affaird_id = #{affairdId}
+    </update>
+    <update id="update">
+        update t_solve_affairs set handle_num = #{handleNum},update_time=#{updateTime} where create_time = #{createTime} and handle_type = #{handleType}
+    </update>
+    <select id="findAll" resultType="java.lang.Integer">
+        SELECT
+            t1.handle_num
+        FROM
+            t_solve_affairs t1
+                JOIN ( SELECT handle_type, MAX( create_time ) AS latest_create_time FROM t_solve_affairs GROUP BY handle_type ) t2 ON t1.handle_type = t2.handle_type
+                AND t1.create_time = t2.latest_create_time
+        ORDER BY
+            t1.handle_type;
+    </select>
+    <select id="findByDateAndType" resultType="com.example.nngkxxdp.entity.SolveAffairs">
+        SELECT * FROM t_solve_affairs WHERE DATE(create_time) = #{date} AND handle_type = #{handleType} LIMIT 1
+    </select>
+    <select id="findByMonthAndType" resultType="com.example.nngkxxdp.entity.SolveAffairs">
+        SELECT * FROM t_solve_affairs WHERE MONTH(create_time) = #{month} AND handle_type = #{handleType}
+    </select>
+
+</mapper>