From 23bd719cebe5feeff4e48fde925b0b39755eea93 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期二, 15 十一月 2022 10:59:50 +0800
Subject: [PATCH] 2022.11.15

---
 src/main/kotlin/cn/flightfeather/supervision/timingtask/TaskLedgerRemind.kt |   74 ++++++++++++++++++++++++++++++++++--
 1 files changed, 69 insertions(+), 5 deletions(-)

diff --git a/src/main/kotlin/cn/flightfeather/supervision/timingtask/TaskLedgerRemind.kt b/src/main/kotlin/cn/flightfeather/supervision/timingtask/TaskLedgerRemind.kt
index 8fc78f4..b8ac686 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/timingtask/TaskLedgerRemind.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/timingtask/TaskLedgerRemind.kt
@@ -1,39 +1,103 @@
 package cn.flightfeather.supervision.timingtask
 
 import cn.flightfeather.supervision.common.wx.TemplateManager
+import cn.flightfeather.supervision.domain.entity.LedgerSubType
 import cn.flightfeather.supervision.domain.entity.MsgSubscribeWx
+import cn.flightfeather.supervision.domain.enumeration.SceneType
+import cn.flightfeather.supervision.domain.mapper.LedgerSubTypeMapper
 import cn.flightfeather.supervision.domain.mapper.MsgSubscribeWxMapper
+import cn.flightfeather.supervision.domain.mapper.UserInfoWxMapper
+import cn.flightfeather.supervision.domain.mapper.UserinfoMapper
+import cn.flightfeather.supervision.lightshare.service.LedgerService
+import org.slf4j.Logger
+import org.slf4j.LoggerFactory
 import org.springframework.stereotype.Component
 import tk.mybatis.mapper.entity.Example
 import java.time.LocalDateTime
+import java.time.format.DateTimeFormatter
 
 /**
  * 鍙拌处涓婁紶鍊掕鏃舵彁閱�
  */
 @Component
 class TaskLedgerRemind(
-    private val msgSubscribeWxMapper: MsgSubscribeWxMapper
+    private val msgSubscribeWxMapper: MsgSubscribeWxMapper,
+    private val userInfoWxMapper: UserInfoWxMapper,
+    private val userinfoMapper: UserinfoMapper,
+    private val ledgerSubTypeMapper: LedgerSubTypeMapper,
+    private val ledgerService: LedgerService,
+    private val templateManager: TemplateManager
 ) : BaseTimingTask() {
+
+    private val LOGGER: Logger? = LoggerFactory.getLogger(TaskLedgerRemind::class.java)
+
+    //鍦烘櫙鍜屽搴旂殑鍙拌处绫诲瀷
+    private val ledgerTypeMap = mutableMapOf<String, MutableList<LedgerSubType>>()
 
     override val period: Long
         get() = 1440L
 
     override fun doTask(localtime: LocalDateTime) {
+        LOGGER?.info("===========寮�濮嬫墽琛屽彴璐︽彁閱掓帹閫佷换鍔�===============")
         //1.閫夋嫨宸茶闃呬簡璇ユ潯鎻愰啋鐨勫井淇$敤鎴�
         val ms = msgSubscribeWxMapper.selectByExample(Example(MsgSubscribeWx::class.java).apply {
             createCriteria().andEqualTo("msTemplateId", TemplateManager.TEMPLATE_1)
                 .andGreaterThan("msCount", 0)
+                .andEqualTo("msAccept", true)
         })
-        //2.鏌ユ壘寰俊鐢ㄦ埛缁戝畾鐨勫満鏅彴璐︿笂浼犳儏鍐�
-        //3.鏍规嵁缁熻缁撴灉鍐冲畾鏄惁鍙戦�佹彁閱掓帹閫�
+        LOGGER?.info("=> 鍙帴鏀舵帹閫佺殑寰俊鐢ㄦ埛鎬绘暟涓猴細${ms.size}")
+        var count = 0
+        ms.forEach {
+            //2.鏌ユ壘寰俊鐢ㄦ埛缁戝畾鐨勫満鏅彴璐︿笂浼犳儏鍐�
+            val uInfoWx = userInfoWxMapper.selectByPrimaryKey(it?.msOpenId) ?: return@forEach
+            val userinfo = userinfoMapper.selectByPrimaryKey(uInfoWx.uiGuid) ?: return@forEach
+            if (userinfo.extension2 == null) {
+                LOGGER?.error("鐢ㄦ埛[${userinfo.acountname}]鐨勫満鏅被鍨嬪瓧娈典负绌�")
+                return@forEach
+            }
+
+            //2.1 鑾峰彇鐢ㄦ埛瀵瑰簲鐨勫彴璐︾被鍨�
+            val ledgerSubTypes = if (ledgerTypeMap.containsKey(userinfo.extension2)) {
+                ledgerTypeMap[userinfo.extension2]
+            } else {
+                ledgerSubTypeMapper.selectByExample(Example(LedgerSubType::class.java).apply {
+                    createCriteria().andEqualTo("lScenetype", userinfo.extension2)
+                    orderBy("lTypeid")
+                })
+            }
+            //2.2 鑾峰彇鐢ㄦ埛褰撳墠鏈堜唤鐨勬彁浜よ褰�
+            val records = ledgerService.getLedgerRecords(uInfoWx.uiGuid, null, userinfo.extension2!!.toInt(), localtime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))
+            var mustTotal = 0//蹇呭~椤规�绘暟
+            var mustCount = 0//蹇呭~椤逛笂浼犳暟
+            ledgerSubTypes?.forEach { t ->
+                if (t.getlNeedupdate()) mustTotal++
+
+                for (r in records) {
+                    if (t.lsSubtypeid == r.lsSubtypeid) {
+                        mustCount++
+                        break
+                    }
+                }
+            }
+            //3.鏍规嵁缁熻缁撴灉鍐冲畾鏄惁鍙戦�佹彁閱掓帹閫�
+            if (mustCount < mustTotal) {
+                val leftDay = 10 - localtime.dayOfMonth
+                templateManager.sendMsg(0, it!!.msOpenId,
+                    listOf("鍙拌处涓婁紶", "${localtime.year}骞�${localtime.monthValue}鏈�10鏃�", leftDay.toString(), "璇烽噸鐐瑰叧娉ㄧ幇鍦鸿嚜瀵绘煡閮ㄥ垎"))
+                count++
+            }
+        }
+        LOGGER?.info("=> 瀹為檯鎺ㄩ�佺殑寰俊鐢ㄦ埛鏁颁负锛�${count}")
+        LOGGER?.info("===========鍙拌处鎻愰啋鎺ㄩ�佷换鍔$粨鏉�===============")
     }
 
     /**
-     * 鍙拌处鎻愰啋浠诲姟瀹氫负姣忔湀5鍙锋棭涓�10鐐规彁閱掑綋鏈�10鍙蜂箣鍓嶆彁浜ゅ彴璐�
+     * 鍙拌处鎻愰啋浠诲姟瀹氫负姣忔湀5鍙锋垨9鍙锋棭涓�10鐐规彁閱掑綋鏈�10鍙蜂箣鍓嶆彁浜ゅ彴璐�
      */
     override fun execute(localtime: LocalDateTime) {
-        if (localtime.dayOfMonth == 5) {
+        if (localtime.dayOfMonth == 5 || localtime.dayOfMonth == 9) {
             doTask(localtime)
+
         }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3