| | |
| | | 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) |
| | | |
| | | } |
| | | } |
| | | } |