From 027bf7da7a012fa36f8835b2419c74da8b2f1c28 Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期二, 15 十一月 2022 11:00:21 +0800 Subject: [PATCH] 2022.11.15 --- src/main/kotlin/cn/flightfeather/supervision/timingtask/FetchVOC.kt | 113 ++++++++++++++++ src/main/kotlin/cn/flightfeather/supervision/push/PushService.kt | 103 ++++++++++++++ src/main/kotlin/cn/flightfeather/supervision/timingtask/PushFume.kt | 163 +++++++++++++++++++++++ ledgerserver.rar | 0 4 files changed, 379 insertions(+), 0 deletions(-) diff --git a/ledgerserver.rar b/ledgerserver.rar new file mode 100644 index 0000000..959d941 --- /dev/null +++ b/ledgerserver.rar Binary files differ diff --git a/src/main/kotlin/cn/flightfeather/supervision/push/PushService.kt b/src/main/kotlin/cn/flightfeather/supervision/push/PushService.kt new file mode 100644 index 0000000..c9014b7 --- /dev/null +++ b/src/main/kotlin/cn/flightfeather/supervision/push/PushService.kt @@ -0,0 +1,103 @@ +package cn.flightfeather.supervision.push + +import com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase.getRequestId +import com.aliyuncs.push.model.v20160801.PushResponse +import com.aliyuncs.utils.ParameterHelper +import com.aliyuncs.push.model.v20160801.PushRequest +import com.aliyuncs.DefaultAcsClient +import com.aliyuncs.profile.DefaultProfile +import com.aliyuncs.profile.IClientProfile +import java.util.* + + +/** + * 绉诲姩鎺ㄩ�佹湇鍔� + * @author riku + * Date: 2019/12/26 + */ +class PushService { + + private val pushRequest: PushRequest + private val client: DefaultAcsClient + + companion object { + const val accessKeyId = "LTAI4FvmhG97saKL33tDqUV8" + const val accessKeySecret = "3PyluVDS97GTGVmm1p3s6vbLkyqZMf" + const val appKey = 28232249L + } + + init { + val profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret) + client = DefaultAcsClient(profile) + pushRequest = PushRequest() + pushRequest.appKey = appKey + pushRequest.pushType = "NOTICE" // 娑堟伅绫诲瀷 MESSAGE NOTICE + pushRequest.deviceType = "ANDROID" // 璁惧绫诲瀷 ANDROID iOS ALL. + setAndroid() + // 鎺ㄩ�佹帶鍒� +// val pushDate = Date(System.currentTimeMillis()) // 30绉掍箣闂寸殑鏃堕棿鐐�, 涔熷彲浠ヨ缃垚浣犳寚瀹氬浐瀹氭椂闂� +// val pushTime = ParameterHelper.getISO8601Time(pushDate) +// pushRequest.pushTime = pushTime // 寤跺悗鎺ㄩ�併�傚彲閫夛紝濡傛灉涓嶈缃〃绀虹珛鍗虫帹閫� + val expireTime = ParameterHelper.getISO8601Time(Date(System.currentTimeMillis() + 12 * 3600 * 1000)) // 12灏忔椂鍚庢秷鎭け鏁�, 涓嶄細鍐嶅彂閫� + pushRequest.expireTime = expireTime + pushRequest.storeOffline = true // 绂荤嚎娑堟伅鏄惁淇濆瓨,鑻ヤ繚瀛�, 鍦ㄦ帹閫佹椂鍊欙紝鐢ㄦ埛鍗充娇涓嶅湪绾匡紝涓嬩竴娆′笂绾垮垯浼氭敹鍒� + } + + fun pushByAccount(accountList: List<String>, all: Boolean = false) { + // 鎺ㄩ�佺洰鏍� + val accounts = StringBuilder() + accountList.forEach { + if (accounts.isNotEmpty()) { + accounts.append(",") + } + accounts.append(it) + } + if (all) { + pushRequest.target = "ALL" //鎺ㄩ�佺洰鏍�: DEVICE:鎸夎澶囨帹閫� ALIAS : 鎸夊埆鍚嶆帹閫� ACCOUNT:鎸夊笎鍙锋帹閫� TAG:鎸夋爣绛炬帹閫�; ALL: 骞挎挱鎺ㄩ�� + pushRequest.targetValue = "ALL" //鏍规嵁Target鏉ヨ瀹氾紝濡俆arget=DEVICE, 鍒欏搴旂殑鍊间负 璁惧id1,璁惧id2. 澶氫釜鍊间娇鐢ㄩ�楀彿鍒嗛殧.(甯愬彿涓庤澶囨湁涓�娆℃渶澶�100涓殑闄愬埗) + } else { + pushRequest.target = "ACCOUNT" //鎺ㄩ�佺洰鏍�: DEVICE:鎸夎澶囨帹閫� ALIAS : 鎸夊埆鍚嶆帹閫� ACCOUNT:鎸夊笎鍙锋帹閫� TAG:鎸夋爣绛炬帹閫�; ALL: 骞挎挱鎺ㄩ�� + pushRequest.targetValue = accounts.toString() //鏍规嵁Target鏉ヨ瀹氾紝濡俆arget=DEVICE, 鍒欏搴旂殑鍊间负 璁惧id1,璁惧id2. 澶氫釜鍊间娇鐢ㄩ�楀彿鍒嗛殧.(甯愬彿涓庤澶囨湁涓�娆℃渶澶�100涓殑闄愬埗) + } + // pushRequest.setTarget("ALL"); //鎺ㄩ�佺洰鏍�: DEVICE:鎺ㄩ�佺粰璁惧; ACCOUNT:鎺ㄩ�佺粰鎸囧畾甯愬彿,TAG:鎺ㄩ�佺粰鑷畾涔夋爣绛�; ALL: 鎺ㄩ�佺粰鍏ㄩ儴 +// pushRequest.setTargetValue("ALL"); //鏍规嵁Target鏉ヨ瀹氾紝濡俆arget=DEVICE, 鍒欏搴旂殑鍊间负 璁惧id1,璁惧id2. 澶氫釜鍊间娇鐢ㄩ�楀彿鍒嗛殧.(甯愬彿涓庤澶囨湁涓�娆℃渶澶�100涓殑闄愬埗) + } + + fun push(title: String, body: String) { + // 鎺ㄩ�侀厤缃� + pushRequest.title = title // 娑堟伅鐨勬爣棰� + pushRequest.body = body // 娑堟伅鐨勫唴瀹� + val pushResponse = client.getAcsResponse(pushRequest, true, 3) + System.out.printf("RequestId: %s, MessageID: %s\n", + pushResponse.requestId, pushResponse.messageId) + } + + private fun setIOS() { + // 鎺ㄩ�侀厤缃�: iOS + pushRequest.iosBadge = 5 // iOS搴旂敤鍥炬爣鍙充笂瑙掕鏍� + pushRequest.iosMusic = "default" // iOS閫氱煡澹伴煶 + pushRequest.iosSubtitle = "iOS10 subtitle"//iOS10閫氱煡鍓爣棰樼殑鍐呭 + pushRequest.iosNotificationCategory = "iOS10 Notification Category"//鎸囧畾iOS10閫氱煡Category + pushRequest.iosMutableContent = true//鏄惁鍏佽鎵╁睍iOS閫氱煡鍐呭 + pushRequest.iosApnsEnv = "DEV"//iOS鐨勯�氱煡鏄�氳繃APNs涓績鏉ュ彂閫佺殑锛岄渶瑕佸~鍐欏搴旂殑鐜淇℃伅銆�"DEV" : 琛ㄧず寮�鍙戠幆澧� "PRODUCT" : 琛ㄧず鐢熶骇鐜 + pushRequest.iosRemind = true // 娑堟伅鎺ㄩ�佹椂璁惧涓嶅湪绾匡紙鏃笌绉诲姩鎺ㄩ�佺殑鏈嶅姟绔殑闀胯繛鎺ラ�氶亾涓嶉�氾級锛屽垯杩欐潯鎺ㄩ�佷細鍋氫负閫氱煡锛岄�氳繃鑻规灉鐨凙PNs閫氶亾閫佽揪涓�娆°�傛敞鎰忥細绂荤嚎娑堟伅杞�氱煡浠呴�傜敤浜庣敓浜х幆澧� + pushRequest.iosRemindBody = "iOSRemindBody"//iOS娑堟伅杞�氱煡鏃朵娇鐢ㄧ殑iOS閫氱煡鍐呭锛屼粎褰搃OSApnsEnv=PRODUCT && iOSRemind涓簍rue鏃舵湁鏁� + pushRequest.iosExtParameters = "{\"_ENV_\":\"DEV\",\"k2\":\"v2\"}" //閫氱煡鐨勬墿灞曞睘鎬�(娉ㄦ剰 : 璇ュ弬鏁拌浠son map鐨勬牸寮忎紶鍏�,鍚﹀垯浼氳В鏋愬嚭閿�) + } + + private fun setAndroid() { + // 鎺ㄩ�侀厤缃�: Android + pushRequest.androidNotifyType = "BOTH"//閫氱煡鐨勬彁閱掓柟寮� "VIBRATE" : 闇囧姩 "SOUND" : 澹伴煶 "BOTH" : 澹伴煶鍜岄渿鍔� NONE : 闈欓煶 + pushRequest.androidNotificationChannel = "1" +// pushRequest.androidNotificationBarType = 1//閫氱煡鏍忚嚜瀹氫箟鏍峰紡0-100 +// pushRequest.androidNotificationBarPriority = 1//閫氱煡鏍忚嚜瀹氫箟鏍峰紡0-100 + pushRequest.androidOpenType = "APPLICATION" //鐐瑰嚮閫氱煡鍚庡姩浣� "APPLICATION" : 鎵撳紑搴旂敤 "ACTIVITY" : 鎵撳紑AndroidActivity "URL" : 鎵撳紑URL "NONE" : 鏃犺烦杞� +// pushRequest.androidOpenUrl = "http://www.aliyun.com" //Android鏀跺埌鎺ㄩ�佸悗鎵撳紑瀵瑰簲鐨剈rl,浠呭綋AndroidOpenType="URL"鏈夋晥 +// pushRequest.androidActivity = "com.alibaba.push2.demo.XiaoMiPushActivity" // 璁惧畾閫氱煡鎵撳紑鐨刟ctivity锛屼粎褰揂ndroidOpenType="Activity"鏈夋晥 + pushRequest.androidMusic = "default" // Android閫氱煡闊充箰 +// pushRequest.androidPopupActivity = "com.ali.demo.PopupActivity"//璁剧疆璇ュ弬鏁板悗鍚姩杈呭姪寮圭獥鍔熻兘, 姝ゅ鎸囧畾閫氱煡鐐瑰嚮鍚庤烦杞殑Activity锛堣緟鍔╁脊绐楃殑鍓嶆彁鏉′欢锛�1. 闆嗘垚绗笁鏂硅緟鍔╅�氶亾锛�2. StoreOffline鍙傛暟璁句负true锛� +// pushRequest.androidPopupTitle = "Popup Title" +// pushRequest.androidPopupBody = "Popup Body" +// pushRequest.androidExtParameters = "{\"k1\":\"android\",\"k2\":\"v2\"}" //璁惧畾閫氱煡鐨勬墿灞曞睘鎬с��(娉ㄦ剰 : 璇ュ弬鏁拌浠� json map 鐨勬牸寮忎紶鍏�,鍚﹀垯浼氳В鏋愬嚭閿�) + } +} \ No newline at end of file diff --git a/src/main/kotlin/cn/flightfeather/supervision/timingtask/FetchVOC.kt b/src/main/kotlin/cn/flightfeather/supervision/timingtask/FetchVOC.kt new file mode 100644 index 0000000..5e4c86b --- /dev/null +++ b/src/main/kotlin/cn/flightfeather/supervision/timingtask/FetchVOC.kt @@ -0,0 +1,113 @@ +package cn.flightfeather.supervision.timingtask + +import cn.flightfeather.supervision.common.net.VOCHttpService +import cn.flightfeather.supervision.domain.entity.DeviceInfo +import cn.flightfeather.supervision.domain.entity.VOCHourValue +import cn.flightfeather.supervision.domain.enumeration.DistrictType +import cn.flightfeather.supervision.domain.enumeration.SceneType +import cn.flightfeather.supervision.domain.mapper.DeviceInfoMapper +import cn.flightfeather.supervision.domain.mapper.VOCHourValueMapper +import cn.flightfeather.supervision.infrastructure.utils.DateUtil +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.stereotype.Component +import tk.mybatis.mapper.entity.Example +import java.time.LocalDateTime +import java.util.* +import javax.annotation.PostConstruct + +/** + * 鑾峰彇voc鐩戞祴鏁版嵁 + */ +@Component +class FetchVOC : BaseTimingTask() { + companion object { + private lateinit var instance: FetchVOC + } + + @Autowired + lateinit var deviceInfoMapper: DeviceInfoMapper + + @Autowired + lateinit var vocHourValueMapper: VOCHourValueMapper + + @PostConstruct + fun init() { + instance = this + } + + override val period: Long + get() = 15L + + override fun doTask(localtime:LocalDateTime) { + getVOCData() + } + + private fun getVOCData() { + val deviceCodeList = mutableListOf<String>() + deviceInfoMapper.selectByExample(Example(DeviceInfo::class.java).apply { + createCriteria().andEqualTo("diProvinceCode", "31") + .andEqualTo("diCityCode", "3100") + .andEqualTo("diDistrictCode", DistrictType.XuHui.code) + .andEqualTo("diSceneTypeId", SceneType.VehicleRepair.value) + .andEqualTo("diDeviceTypeId", 1) + }).forEach { + it?.let { + deviceCodeList.add(it.diCode) + } + } + + val cal = Calendar.getInstance(Locale.CHINA).apply { + set(Calendar.MINUTE, 0) + set(Calendar.SECOND, 0) + } + val endTime = DateUtil.DateToString(cal.time, "yyyy-MM-dd HH:mm:ss") ?: "" + cal.add(Calendar.HOUR_OF_DAY, -1) + val startTime = DateUtil.DateToString(cal.time, "yyyy-MM-dd HH:mm:ss") ?: "" + + deviceCodeList.forEach { + val deviceInfo = VOCHttpService.DeviceInfo(listOf(it), startTime, endTime) +// threadPoo?.execute { + VOCHttpService.getVOCData(deviceInfo)?.run { + try { + if (this["code"].asInt == 200) { + val data = this["data"].asJsonObject + data["rtdMinuteHourDayBeans"].asJsonArray.forEach {e -> + e.asJsonObject.let { o-> + val hourValue = VOCHourValue() + + hourValue.vocStatCode = o["deviceCode"].asString + + val collectTime = o["collectTime"].asString + hourValue.vocDataTime = DateUtil.StringToDate(collectTime) + + o["minuteHourDayValueBeans"].asJsonArray.forEach {e1 -> + e1.asJsonObject.let {o1 -> + when (o1["factorCode"].asString) { + "e70201" -> hourValue.vocFanElectricity1 = o1["factorAvg"].asDouble + "e70202" -> hourValue.vocFanElectricity2 = o1["factorAvg"].asDouble + "e70203" -> hourValue.vocFanElectricity3 = o1["factorAvg"].asDouble + "e70204" -> hourValue.vocFanElectricity4 = o1["factorAvg"].asDouble + "e70205" -> hourValue.vocFanElectricity5 = o1["factorAvg"].asDouble + "e70206" -> hourValue.vocFanElectricity6 = o1["factorAvg"].asDouble + "g29001" -> hourValue.vocValue = o1["factorAvg"].asDouble + } + } + } + val r = vocHourValueMapper.selectByExample(Example(VOCHourValue::class.java).apply { + createCriteria().andEqualTo("vocDataTime", hourValue.vocDataTime) + .andEqualTo("vocStatCode", it) + }) + if (r.isEmpty()) { + vocHourValueMapper.insertSelective(hourValue) + } + } + } + } + } catch (e: Throwable) { + e.printStackTrace() + } + } +// } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/cn/flightfeather/supervision/timingtask/PushFume.kt b/src/main/kotlin/cn/flightfeather/supervision/timingtask/PushFume.kt new file mode 100644 index 0000000..b2e4007 --- /dev/null +++ b/src/main/kotlin/cn/flightfeather/supervision/timingtask/PushFume.kt @@ -0,0 +1,163 @@ +package cn.flightfeather.supervision.timingtask + +import cn.flightfeather.supervision.common.net.FumeHttpService +import cn.flightfeather.supervision.domain.entity.DeviceInfo +import cn.flightfeather.supervision.domain.entity.FumeMinuteValue +import cn.flightfeather.supervision.domain.enumeration.DistrictType +import cn.flightfeather.supervision.domain.enumeration.SceneType +import cn.flightfeather.supervision.domain.mapper.DeviceInfoMapper +import cn.flightfeather.supervision.domain.mapper.FumeMinuteValueMapper +import cn.flightfeather.supervision.infrastructure.utils.DateUtil +import com.github.pagehelper.PageHelper +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.stereotype.Component +import tk.mybatis.mapper.entity.Example +import java.time.LocalDateTime +import java.time.LocalTime +import java.time.ZoneId +import java.time.ZoneOffset +import java.time.format.DateTimeFormatter +import java.util.* +import javax.annotation.PostConstruct +import kotlin.math.round + +/** + * 涓婁紶娌圭儫鐩戞祴鏁版嵁 + */ +@Component +class PushFume : BaseTimingTask() { + + companion object { +// private lateinit var instance: PushFume + val LOGGER = LoggerFactory.getLogger(PushFume::class.java) + } + + @Autowired + lateinit var deviceInfoMapper: DeviceInfoMapper + + @Autowired + lateinit var fumeMinuteValueMapper: FumeMinuteValueMapper + +// @PostConstruct +// fun init() { +// instance = this +// } + + private val deviceCodeList = mutableListOf<String>() + + override val period: Long + get() = 1L + + override fun doTask(localtime: LocalDateTime) { + LOGGER.info("===========寮�濮嬫墽琛屾补鐑熸暟鎹笂浼犱换鍔�===============") + // 鍒锋柊鐩戞祴鐐圭紪鍙� + refreshDeviceCode() + + //姣�10鍒嗛挓璁$畻涓�娆″钩鍧囧�煎苟涓婁紶 + // FIXME: 2021/4/8 鍧囧�肩殑璁$畻閫昏緫涔嬪悗搴旇鏀惧埌鍏朵粬妯″潡 + val min = localtime.minute + if (min != 0 && min != 10 && min != 20 && min != 30 && min != 40 && min != 50) return + + //璁$畻鍙栧�兼椂闂� + val endTime = Date.from(localtime.minusMinutes(1).withSecond(59).atZone(ZoneId.systemDefault()).toInstant()) + val startTime = Date.from(localtime.minusMinutes(10).withSecond(0).atZone(ZoneId.systemDefault()).toInstant()) + + //鐢熸垚涓婁紶鏁版嵁缁撴瀯浣� + val postData = FumeHttpService.PostData() + val allData = mutableListOf<FumeMinuteValue>() + deviceCodeList.forEach { + //鑾峰彇鍓�10鍒嗛挓鐨勬暟鎹� + val dataList = fumeMinuteValueMapper.selectByExample(Example(FumeMinuteValue::class.java).apply { + createCriteria().andEqualTo("mvStatCode", it) + .andBetween("mvCreateTime", startTime, endTime) + and(createCriteria().orIsNull("mvUpload") + .orEqualTo("mvUpload", false)) + }) + + //璁$畻鍧囧�� + var count = 0 + var total = 0.0 + dataList.forEach { + total += it.mvFumeConcentration2 + if (it.mvFumeConcentration2 != 0.0) { + count++ + } + } + if (count == 0) { + dataUpdate(dataList) + return@forEach + } + val average = round(total / count * 100) / 100 + + //鍧囧�肩瓑浜�0锛屼笉涓婃姤锛岀洿鎺ユ洿鏂颁笂浼犵姸鎬� + if (average == 0.0) { + dataUpdate(dataList) + return@forEach + } + + //鐢熸垚涓婁紶鏁版嵁缁撴瀯浣� + dataList.last().let { + postData.data.add(FumeHttpService.FumeData( + "hengzhiyuan_${it.mvStatCode}", + DateUtil.DateToString(startTime, DateUtil.DateStyle.YYYY_MM_DD_HH_MM_SS), + 0.0, average, + if (it.mvFanStatus) 3 else 2, + it.mvFanElectricity, 0, + if (it.mvPurifierStatus) 3 else 2, + it.mvPurifierElectricity, 0, + 0, 0.0 + )) + } + + allData.addAll(dataList) + } + + //涓婁紶鏁版嵁骞舵洿鏂版暟鎹姸鎬� + LOGGER.info("===========鏁版嵁閲囨牱鏃堕棿锛�$localtime") + postData.data.forEach { + LOGGER.info("${it.equipmentShowId} ** ${it.dataTime}") + } + LOGGER.info("=================================") + FumeHttpService.uploadData(postData)?.run { + LOGGER.info(this.toString()) + if (this["code"].asInt == 0 && this["data"].asInt > 0) { + dataUpdate(allData) + } + LOGGER.info("===========娌圭儫鏁版嵁涓婁紶浠诲姟缁撴潫============") + } + } + + /** + * 鍒锋柊鐩戞祴鐐圭紪鍙� + */ + @Synchronized + private fun refreshDeviceCode() { + val now = LocalDateTime.now() + if (deviceCodeList.isEmpty() || (now.hour == 0 && now.minute <= period)) { + deviceCodeList.clear() + deviceInfoMapper.selectByExample(Example(DeviceInfo::class.java).apply { + createCriteria().andEqualTo("diProvinceCode", "31") + .andEqualTo("diCityCode", "3100") + .andEqualTo("diDistrictCode", DistrictType.XuHui.code) + .andEqualTo("diSceneTypeId", SceneType.Restaurant.value) + .andEqualTo("diDeviceTypeId", 1) + .andEqualTo("diSupplier", "hengzhiyuan") + }).forEach { + it?.let { + deviceCodeList.add(it.diCode) + } + } + } + } + + /** + * 鏇存柊鏁版嵁鐘舵�� + */ + private fun dataUpdate(dataList: List<FumeMinuteValue>) { + dataList.forEach { + it.mvUpload = true + fumeMinuteValueMapper.updateByPrimaryKey(it) + } + } +} \ No newline at end of file -- Gitblit v1.9.3