diff --git a/device-manager-ui/admin/src/views/Home.vue b/device-manager-ui/admin/src/views/Home.vue index b84a42d5a9190bef9fe943adea3e6457aa2c35b7..e919bbc54b01276c0e66f8f9c5f898774510a0fd 100644 --- a/device-manager-ui/admin/src/views/Home.vue +++ b/device-manager-ui/admin/src/views/Home.vue @@ -10,11 +10,20 @@ <el-button type="text" size="mini" >鏁版嵁鏇存柊:{{ formatterDate(statData.updateTime) }}</el-button > - <el-button icon="el-icon-refresh" size="mini" type="text">鎵嬪姩鍒锋柊</el-button> + <el-button + icon="el-icon-refresh" + size="mini" + @click="syncDeviceStat" + type="text" + >鎵嬪姩鍒锋柊</el-button + > </el-row> <el-card style="margin-left: 50px; margin-right: 50px; margin-top: 10px"> - <el-row :gutter="20" style="height:80px;align-items: center;margin-top:10px" > + <el-row + :gutter="20" + style="height: 80px; align-items: center; margin-top: 10px" + > <el-col :span="3"> <el-row type="flex" justify="center"> <span style="font-size: 20px" @@ -22,8 +31,19 @@ ></el-row > <el-row type="flex" justify="center"> - <span style="font-size: 12px;" - ><span style="color:#6182f6">鏄ㄦ棩 </span ><span v-bind:class="{success: statData.deviceAddCount>=0, warn: statData.deviceAddCount<0}">{{ statData.deviceAddCount>=0?'+'+statData.deviceAddCount:"-"+statData.deviceAddCount }}</span></span + <span style="font-size: 12px" + ><span style="color: #6182f6">鏄ㄦ棩 </span + ><span + v-bind:class="{ + success: statData.deviceAddCount >= 0, + warn: statData.deviceAddCount < 0, + }" + >{{ + statData.deviceAddCount >= 0 + ? "+" + statData.deviceAddCount + : "-" + statData.deviceAddCount + }}</span + ></span ></el-row > <el-row type="flex" justify="center"> @@ -39,8 +59,19 @@ ></el-row > <el-row type="flex" justify="center"> - <span style="font-size: 12px;" - ><span style="color:#6182f6">鏄ㄦ棩 </span ><span v-bind:class="{success: statData.siteAddCount>=0, warn: statData.siteAddCount<0}">{{ statData.siteAddCount>=0?'+'+statData.siteAddCount:"-"+statData.siteAddCount }}</span></span + <span style="font-size: 12px" + ><span style="color: #6182f6">鏄ㄦ棩 </span + ><span + v-bind:class="{ + success: statData.siteAddCount >= 0, + warn: statData.siteAddCount < 0, + }" + >{{ + statData.siteAddCount >= 0 + ? "+" + statData.siteAddCount + : "-" + statData.siteAddCount + }}</span + ></span ></el-row > <el-row type="flex" justify="center"> @@ -56,9 +87,13 @@ ></el-row > - <el-row type="flex" justify="center"> - <span style="font-size: 12px;" - ><span style="color:#6182f6">涓婄嚎鐜� </span ><span v-bind:class="{success: statData.deviceOnlineRatio>=0}">{{ statData.deviceOnlineRatio* 100 }}%</span></span + <el-row type="flex" justify="center"> + <span style="font-size: 12px" + ><span style="color: #6182f6">涓婄嚎鐜� </span + ><span + v-bind:class="{ success: statData.deviceOnlineRatio >= 0 }" + >{{ statData.deviceOnlineRatio * 100 }}%</span + ></span ></el-row > <el-row type="flex" justify="center"> @@ -74,8 +109,11 @@ ></el-row > <el-row type="flex" justify="center"> - <span style="font-size: 12px;" - ><span style="color:#6182f6">绂荤嚎鐜� </span ><span v-bind:class="{warn: statData.deviceOfflineRatio>=0}">{{ statData.deviceOfflineRatio* 100 }}%</span></span + <span style="font-size: 12px" + ><span style="color: #6182f6">绂荤嚎鐜� </span + ><span v-bind:class="{ warn: statData.deviceOfflineRatio >= 0 }" + >{{ statData.deviceOfflineRatio * 100 }}%</span + ></span ></el-row > <el-row type="flex" justify="center"> @@ -90,9 +128,12 @@ ><b>{{ statData.deviceStopRatio }}</b></span ></el-row > - <el-row type="flex" justify="center"> - <span style="font-size: 12px;" - ><span style="color:#6182f6">鍋滅敤鐜� </span ><span v-bind:class="{warn: statData.deviceStopRatio>=0}">{{ statData.deviceStopRatio* 100 }}%</span></span + <el-row type="flex" justify="center"> + <span style="font-size: 12px" + ><span style="color: #6182f6">鍋滅敤鐜� </span + ><span v-bind:class="{ warn: statData.deviceStopRatio >= 0 }" + >{{ statData.deviceStopRatio * 100 }}%</span + ></span ></el-row > <el-row type="flex" justify="center"> @@ -108,8 +149,19 @@ ></el-row > <el-row type="flex" justify="center"> - <span style="font-size: 12px;" - ><span style="color:#6182f6">鏄ㄦ棩 </span ><span v-bind:class="{success: statData.alarmAddCount>=0, warn: statData.alarmAddCount<0}">{{ statData.alarmAddCount>=0?'+'+statData.alarmAddCount:"-"+statData.alarmAddCount }}</span></span + <span style="font-size: 12px" + ><span style="color: #6182f6">鏄ㄦ棩 </span + ><span + v-bind:class="{ + success: statData.alarmAddCount >= 0, + warn: statData.alarmAddCount < 0, + }" + >{{ + statData.alarmAddCount >= 0 + ? "+" + statData.alarmAddCount + : "-" + statData.alarmAddCount + }}</span + ></span ></el-row > <el-row type="flex" justify="center"> @@ -118,35 +170,46 @@ > </el-row> </el-col> - <el-col :span="3" > - <el-row type="flex" justify="center" + <el-col :span="3"> + <el-row type="flex" justify="center" ><span style="font-size: 20px" ><b>{{ statData.pushTotalCount }}</b></span ></el-row > - - <el-row type="flex" justify="center"> - <span style="font-size: 12px;" - ><span style="color:#6182f6">鏄ㄦ棩 </span ><span v-bind:class="{success: statData.pushAddCount>=0, warn: statData.pushAddCount<0}">{{ statData.pushAddCount>=0?'+'+statData.pushAddCount:"-"+statData.pushAddCount }}</span></span + + <el-row type="flex" justify="center"> + <span style="font-size: 12px" + ><span style="color: #6182f6">鏄ㄦ棩 </span + ><span + v-bind:class="{ + success: statData.pushAddCount >= 0, + warn: statData.pushAddCount < 0, + }" + >{{ + statData.pushAddCount >= 0 + ? "+" + statData.pushAddCount + : "-" + statData.pushAddCount + }}</span + ></span ></el-row > - - <el-row type="flex" justify="center"> + + <el-row type="flex" justify="center"> <el-button icon="el-icon-data-board" size="mini" type="text" >浠婃棩娑堟伅鎺ㄩ€�</el-button > </el-row> </el-col> - <el-col :span="3" type="flex" style="height:100%" > - <el-row type="flex" style="margin-top:6px" justify="center" + <el-col :span="3" type="flex" style="height: 100%"> + <el-row type="flex" style="margin-top: 6px" justify="center" ><span style="font-size: 13px" - ><span style="color:#6182f6">浠婃棩涓嬪彂鍛戒护 </span> + ><span style="color: #6182f6">浠婃棩涓嬪彂鍛戒护 </span> <b>{{ statData.uploadMessageTotalCount }}</b></span ></el-row > - <el-row type="flex" style="margin-top:6px" justify="center" + <el-row type="flex" style="margin-top: 6px" justify="center" ><span style="font-size: 13px" - ><span style="color:#6182f6">浠婃棩涓嬪彂鍛戒护 </span> + ><span style="color: #6182f6">浠婃棩涓嬪彂鍛戒护 </span> <b>{{ statData.downloadMessageTotalCount }}</b></span ></el-row > @@ -213,9 +276,7 @@ export default { this.$post("/device/stat/list", query) .then((res) => { if (res.code == 1) { - console.log("res", res); this.statData = res.data.data[0]; - console.log("statData", this.statData); } this.loading = false; }) @@ -237,6 +298,20 @@ export default { console.log("process", process.env); }, methods: { + syncDeviceStat() { + this.$post("/device/stat/syncDeviceStat", {}) + .then((res) => { + if (res.code == 1) { + this.statData = res.data.data[0]; + } else { + this.$message.error(res.msg); + } + }) + .catch((error) => { + this.$message.error(error.message); + }); + }, + findDeviceTotalStat(beforeday) { let query = { createTimeStart: this.formatterDate(beforeday) }; this.$post("/device/stat/list", query) @@ -709,26 +784,25 @@ export default { </script> <style scoped> -.success{ - color:green +.success { + color: green; } -.warn{ +.warn { color: rgb(215, 25, 25); } .homeIndex { - display: inline-block; - position: relative; + display: inline-block; + position: relative; } .homeIndex::before { - content: ''; - position: absolute; - top: 0; - left: 0; - width: 100%; - height: 35%; - background: #1848c8; + content: ""; + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 35%; + background: #1848c8; } - </style> diff --git a/device-manager/src/main/java/com/mortals/xhx/daemon/task/DeviceTotalStatTaskImpl.java b/device-manager/src/main/java/com/mortals/xhx/daemon/task/DeviceTotalStatTaskImpl.java index f746f8e9b0f2d3d252af62f1630dc18177c1323f..f84ca2b2d774c272412b24ce2a204eabc1540c2f 100644 --- a/device-manager/src/main/java/com/mortals/xhx/daemon/task/DeviceTotalStatTaskImpl.java +++ b/device-manager/src/main/java/com/mortals/xhx/daemon/task/DeviceTotalStatTaskImpl.java @@ -62,7 +62,8 @@ public class DeviceTotalStatTaskImpl implements ITaskExcuteService { @Override public void excuteTask(ITask task) throws AppException { - doDeviceStat(); + deviceService.deviceStat(null); + //doDeviceStat(); } diff --git a/device-manager/src/main/java/com/mortals/xhx/module/device/service/DeviceService.java b/device-manager/src/main/java/com/mortals/xhx/module/device/service/DeviceService.java index 405d8f9121fcd38d9ec15c79e2ee666b92b8636a..6a33c4abe09f1a7b5346a7d6d9052810fd07b3ea 100644 --- a/device-manager/src/main/java/com/mortals/xhx/module/device/service/DeviceService.java +++ b/device-manager/src/main/java/com/mortals/xhx/module/device/service/DeviceService.java @@ -53,6 +53,12 @@ public interface DeviceService extends ICRUDCacheService<DeviceEntity,Long>{ DeviceDao getDeviceDao(); + /** + * 璁惧缁熻褰撳ぉ鎯呭喌 + * @param context + */ + void deviceStat(Context context); + diff --git a/device-manager/src/main/java/com/mortals/xhx/module/device/service/impl/DeviceServiceImpl.java b/device-manager/src/main/java/com/mortals/xhx/module/device/service/impl/DeviceServiceImpl.java index 378d5a1d7a86b5991cae0ae641add1592289df3d..b012df1a1a3b1f80b9aa8e8c4f2ccfc807ae74db 100644 --- a/device-manager/src/main/java/com/mortals/xhx/module/device/service/impl/DeviceServiceImpl.java +++ b/device-manager/src/main/java/com/mortals/xhx/module/device/service/impl/DeviceServiceImpl.java @@ -1,5 +1,6 @@ package com.mortals.xhx.module.device.service.impl; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.PatternPool; import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.URLUtil; @@ -9,18 +10,25 @@ import com.mortals.framework.exception.AppException; import com.mortals.framework.model.Context; import com.mortals.framework.service.ICacheService; import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl; +import com.mortals.framework.util.DateUtils; import com.mortals.xhx.base.system.message.MessageService; import com.mortals.xhx.busiz.req.DeviceReq; import com.mortals.xhx.busiz.rsp.ApiResp; import com.mortals.xhx.common.code.*; import com.mortals.xhx.common.key.Constant; +import com.mortals.xhx.common.pdu.RespData; import com.mortals.xhx.common.pdu.site.SitePdu; import com.mortals.xhx.common.utils.BeanUtil; import com.mortals.xhx.feign.site.ISiteFeign; +import com.mortals.xhx.module.alarm.model.AlarmSmsSendEntity; +import com.mortals.xhx.module.alarm.model.AlarmSmsSendQuery; +import com.mortals.xhx.module.alarm.service.AlarmSmsSendService; import com.mortals.xhx.module.device.dao.DeviceDao; -import com.mortals.xhx.module.device.model.DeviceEntity; -import com.mortals.xhx.module.device.model.DeviceQuery; +import com.mortals.xhx.module.device.model.*; +import com.mortals.xhx.module.device.service.DeviceAlarmInfoService; +import com.mortals.xhx.module.device.service.DeviceLogService; import com.mortals.xhx.module.device.service.DeviceService; +import com.mortals.xhx.module.device.service.DeviceStatService; import com.mortals.xhx.module.platform.model.PlatformEntity; import com.mortals.xhx.module.platform.model.PlatformQuery; import com.mortals.xhx.module.platform.service.PlatformService; @@ -35,7 +43,12 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; +import java.math.BigDecimal; import java.util.*; +import java.util.stream.Collectors; + +import static java.math.BigDecimal.ROUND_HALF_DOWN; +import static java.util.stream.Collectors.counting; /** * DeviceService @@ -56,6 +69,14 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D private DefaultTbCoreConsumerService consumerService; @Autowired private ISiteFeign siteFeign; + @Autowired + private DeviceLogService deviceLogService; + @Autowired + private DeviceStatService deviceStatService; + @Autowired + private DeviceAlarmInfoService deviceAlarmInfoService; + @Autowired + private AlarmSmsSendService alarmSmsSendService; @Override protected String getExtKey(DeviceEntity data) { @@ -130,7 +151,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D } @Override - public ApiResp<String> sendDeviceMessage(DeviceEntity deviceEntity, TopicPartitionInfo info, TbQueueMsgHeaders header, String message,TbQueueCallback callback, Context context) { + public ApiResp<String> sendDeviceMessage(DeviceEntity deviceEntity, TopicPartitionInfo info, TbQueueMsgHeaders header, String message, TbQueueCallback callback, Context context) { ApiResp<String> resp = new ApiResp<>(); resp.setCode(ApiRespCodeEnum.SUCCESS.getValue()); resp.setMsg(ApiRespCodeEnum.SUCCESS.getLabel()); @@ -145,7 +166,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D deviceQuery.setIdList(deviceIds); List<DeviceEntity> deviceEntityList = this.find(deviceQuery); for (DeviceEntity deviceEntity : deviceEntityList) { - resp = sendDeviceMessage(deviceEntity, info, header, message,null, context); + resp = sendDeviceMessage(deviceEntity, info, header, message, null, context); } return resp; } @@ -206,10 +227,10 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D Set<TopicPartitionInfo> set = new HashSet<>(); set.add(topicPartitionInfo); - if(status==YesNoEnum.YES.getValue()){ + if (status == YesNoEnum.YES.getValue()) { //寮€鍚� consumerService.getMainConsumer().subscribe(set); - }else{ + } else { //鍏抽棴 consumerService.getMainConsumer().unsubscribe(set); } @@ -303,6 +324,106 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D return this.getDao(); } + @Override + public void deviceStat(Context context) { + //鏌ヨ褰撳ぉ缁熻锛屽鏋滄湁 鍒欐洿鏂扮粺璁$粨鏋滐紝鍚﹀垯鏂板 + DeviceStatEntity deviceStatEntity = deviceStatService.selectOne(new DeviceStatQuery() + .year(DateUtil.year(new Date())) + .month(DateUtil.month(new Date()) + 1) + .day(DateUtil.dayOfMonth(new Date()))); + if (ObjectUtils.isEmpty(deviceStatEntity)) { + deviceStatEntity = new DeviceStatEntity(); + deviceStatEntity.initAttrValue(); + deviceStatEntity.setCreateTime(new Date()); + deviceStatEntity.setYear(DateUtil.year(new Date())); + deviceStatEntity.setMonth(DateUtil.month(new Date()) + 1); + deviceStatEntity.setDay(DateUtil.dayOfMonth(new Date())); + } + + //鑾峰彇鏄ㄥぉ缁熻鏁版嵁 + DeviceStatEntity yesterdayDeviceStat = deviceStatService.selectOne(new DeviceStatQuery() + .year(DateUtil.year(DateUtil.yesterday())) + .month(DateUtil.month(DateUtil.yesterday()) + 1) + .day(DateUtil.dayOfMonth(DateUtil.yesterday()))); + if (ObjectUtils.isEmpty(yesterdayDeviceStat)) { + yesterdayDeviceStat = new DeviceStatEntity(); + yesterdayDeviceStat.initAttrValue(); + } + try { + //鑾峰彇璁惧鎬绘暟 + List<DeviceEntity> deviceList = this.find(new DeviceQuery()); + Integer deviceTotalCount = deviceList.size(); + + deviceStatEntity.setDeviceTotalCount(deviceTotalCount); + deviceStatEntity.setDeviceAddCount(deviceTotalCount - yesterdayDeviceStat.getDeviceTotalCount()); + + //绔欑偣鏁伴噺 + SitePdu sitePdu = new SitePdu(); + sitePdu.setSize(-1); + Rest<RespData<List<SitePdu>>> resp = siteFeign.list(sitePdu); + + if (resp.getCode() == 1) { + List<SitePdu> sitePduList = resp.getData().getData(); + deviceStatEntity.setSiteTotalCount(sitePduList.size()); + deviceStatEntity.setSiteAddCount(sitePduList.size() - yesterdayDeviceStat.getSiteTotalCount()); + } + + //鍦ㄧ嚎鏁伴噺 + Long deviceOnlineCount = deviceList.parallelStream().filter(f -> f.getDeviceStatus() == DeviceStatusEnum.鍦ㄧ嚎.getValue()).count(); + deviceStatEntity.setDeviceOnlineCount(deviceOnlineCount.intValue()); + deviceStatEntity.setDeviceOnlineRatio(new BigDecimal(deviceOnlineCount).divide(new BigDecimal(deviceList.size()), ROUND_HALF_DOWN).setScale(2)); + + //绂荤嚎鏁伴噺 + Long deviceOfflineCount = deviceList.parallelStream().filter(f -> f.getDeviceStatus() == DeviceStatusEnum.绂荤嚎.getValue()).count(); + deviceStatEntity.setDeviceOfflineCount(deviceOfflineCount.intValue()); + deviceStatEntity.setDeviceOfflineRatio(new BigDecimal(deviceOfflineCount).divide(new BigDecimal(deviceList.size()), ROUND_HALF_DOWN).setScale(2)); + + //鍋滅敤鏁伴噺 + Long deviceStopCount = deviceList.parallelStream().filter(f -> f.getEnabled() == YesNoEnum.NO.getValue()).count(); + deviceStatEntity.setDeviceStopCount(deviceStopCount.intValue()); + deviceStatEntity.setDeviceStopRatio(new BigDecimal(deviceStopCount).divide(new BigDecimal(deviceList.size()), ROUND_HALF_DOWN).setScale(2)); + + //浠婃棩鍛婅鏁伴噺 + DeviceAlarmInfoQuery deviceAlarmInfoQuery = new DeviceAlarmInfoQuery(); + deviceAlarmInfoQuery.setCreateTimeStart(DateUtils.getCurrStrDate()); + deviceAlarmInfoQuery.setCreateTimeEnd(DateUtils.getCurrStrDate()); + List<DeviceAlarmInfoEntity> deviceAlarmInfoList = deviceAlarmInfoService.find(deviceAlarmInfoQuery); + deviceStatEntity.setAlarmTotalCount(deviceAlarmInfoList.size()); + deviceStatEntity.setAlarmAddCount(deviceAlarmInfoList.size() - yesterdayDeviceStat.getAlarmTotalCount()); + + //鎺ㄩ€佹暟閲� + AlarmSmsSendQuery alarmSmsSendQuery = new AlarmSmsSendQuery(); + alarmSmsSendQuery.setSendTimeStart(DateUtils.getCurrStrDate()); + alarmSmsSendQuery.setSendTimeEnd(DateUtils.getCurrStrDate()); + alarmSmsSendQuery.setSendStatus(SendStatusEnum.鍙戦€佹垚鍔�.getValue()); + + List<AlarmSmsSendEntity> alarmSmsSendEntities = alarmSmsSendService.find(alarmSmsSendQuery); + deviceStatEntity.setPushTotalCount(alarmSmsSendEntities.size()); + deviceStatEntity.setPushAddCount(alarmSmsSendEntities.size() - yesterdayDeviceStat.getPushTotalCount()); + + //涓婅涓嬭鏁伴噺 + DeviceLogQuery deviceLogQuery = new DeviceLogQuery(); + deviceLogQuery.setCreateTimeStart(DateUtils.getCurrStrDate()); + deviceLogQuery.setCreateTimeEnd(DateUtils.getCurrStrDate()); + Map<Boolean, Long> collect = deviceLogService.find(deviceLogQuery).parallelStream().collect(Collectors.partitioningBy(x -> x.getLogType() == LogTypeEnum.涓婃姤浜嬩欢.getValue(), counting())); + deviceStatEntity.setUploadMessageTotalCount(collect.getOrDefault(true, 0L).intValue()); + deviceStatEntity.setDownloadMessageTotalCount(collect.getOrDefault(false, 0L).intValue()); + + if (deviceStatEntity.newEntity()) { + deviceStatEntity.setCreateTime(new Date()); + deviceStatService.save(deviceStatEntity); + } else { + deviceStatEntity.setUpdateTime(new Date()); + deviceStatService.update(deviceStatEntity); + } + + + } catch (Exception e) { + log.error("缁熻寮傚父", e); + throw new AppException("缁熻寮傚父!"); + } + } + @Override protected void removeBefore(Long[] ids, Context context) throws AppException { Arrays.asList(ids).stream().forEach(id -> { @@ -366,7 +487,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D DeviceEntity deviceEntity = this.selectOne(new DeviceQuery().deviceCode(entity.getDeviceCode())); if (!ObjectUtils.isEmpty(deviceEntity)) { //濡傛灉鍘熷鐨勫煙褰撳墠鐨勭珯鐐逛笉涓€鑷达紝鍋氭洿鏂板鐞嗭紝鍚﹀垯鎻愮ず缂栫爜閲嶅 - if (!ObjectUtils.isEmpty(entity.getSiteId())&&entity.getSiteId() != deviceEntity.getSiteId()) { + if (!ObjectUtils.isEmpty(entity.getSiteId()) && entity.getSiteId() != deviceEntity.getSiteId()) { entity.setId(deviceEntity.getId()); entity.setUpdateTime(new Date()); entity.setUpdateUserId(getContextUserId(context)); diff --git a/device-manager/src/main/java/com/mortals/xhx/module/device/web/DeviceStatController.java b/device-manager/src/main/java/com/mortals/xhx/module/device/web/DeviceStatController.java index 5e1ff82f3dbde1aaaa61908e5d149b1a871fbf0f..901e33d6e97c4572cf4bc9552e8d7c644c19b5ae 100644 --- a/device-manager/src/main/java/com/mortals/xhx/module/device/web/DeviceStatController.java +++ b/device-manager/src/main/java/com/mortals/xhx/module/device/web/DeviceStatController.java @@ -1,43 +1,52 @@ package com.mortals.xhx.module.device.web; + +import cn.hutool.core.date.DateUtil; +import com.mortals.framework.common.Rest; import com.mortals.framework.web.BaseCRUDJsonBodyMappingController; import com.mortals.xhx.base.system.param.service.ParamService; +import com.mortals.xhx.module.device.model.DeviceStatQuery; +import com.mortals.xhx.module.device.service.DeviceService; +import com.mortals.xhx.module.sitestat.model.SitestatQuery; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.*; import com.mortals.framework.model.Context; + import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import com.mortals.framework.web.BaseCRUDJsonBodyMappingController; import com.mortals.xhx.module.device.model.DeviceStatEntity; import com.mortals.xhx.module.device.service.DeviceStatService; import org.apache.commons.lang3.ArrayUtils; import com.mortals.framework.util.StringUtils; -import java.util.HashMap; -import java.util.List; -import java.util.Map; + +import java.util.*; import java.util.stream.Collectors; + import com.alibaba.fastjson.JSONObject; -import java.util.Arrays; + import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; + import static com.mortals.framework.ap.SysConstains.*; + /** -* -* 璁惧缁熻 -* -* @author zxfei -* @date 2022-07-05 -*/ + * 璁惧缁熻 + * + * @author zxfei + * @date 2022-07-05 + */ @RestController @RequestMapping("device/stat") -public class DeviceStatController extends BaseCRUDJsonBodyMappingController<DeviceStatService,DeviceStatEntity,Long> { +public class DeviceStatController extends BaseCRUDJsonBodyMappingController<DeviceStatService, DeviceStatEntity, Long> { @Autowired - private ParamService paramService; + private DeviceService deviceService; - public DeviceStatController(){ - super.setModuleDesc( "璁惧缁熻"); + public DeviceStatController() { + super.setModuleDesc("璁惧缁熻"); } @Override @@ -46,4 +55,24 @@ public class DeviceStatController extends BaseCRUDJsonBodyMappingController<Devi } + /** + * 绔欑偣淇℃伅 + */ + @PostMapping(value = "syncDeviceStat") + public Rest<Object> syncDeviceStat() { + try { + //鍒锋柊鎴愬姛锛岃繑鍥炲垪琛� + deviceService.deviceStat(getContext()); + DeviceStatQuery deviceStatQuery = new DeviceStatQuery(); + deviceStatQuery.setYear(DateUtil.year(new Date())); + deviceStatQuery.setMonth(DateUtil.month(new Date()) + 1); + deviceStatQuery.setDay(DateUtil.dayOfMonth(new Date())); + Rest<Object> resp = this.list(deviceStatQuery); + return resp; + } catch (Exception e) { + log.error("鍒锋柊寮傚父", e); + return Rest.fail(KEY_RESULT_CODE, super.convertException(e)); + } + } + } \ No newline at end of file diff --git a/device-manager/src/main/java/com/mortals/xhx/module/sitestat/web/SitestatController.java b/device-manager/src/main/java/com/mortals/xhx/module/sitestat/web/SitestatController.java index 17a12696c37a7d8cb3ca3b0ceee3043dfca8745d..1cc0ff03cdcd2b7b8bbcab75a4ed2806ca2dc410 100644 --- a/device-manager/src/main/java/com/mortals/xhx/module/sitestat/web/SitestatController.java +++ b/device-manager/src/main/java/com/mortals/xhx/module/sitestat/web/SitestatController.java @@ -14,11 +14,14 @@ import com.mortals.xhx.common.pdu.site.SitePdu; import com.mortals.xhx.common.pdu.user.UserPdu; import com.mortals.xhx.feign.site.ISiteFeign; import com.mortals.xhx.feign.user.IUserFeign; +import com.mortals.xhx.module.device.service.DeviceService; import com.mortals.xhx.module.sitestat.model.SitestatEntity; +import com.mortals.xhx.module.sitestat.model.SitestatQuery; import com.mortals.xhx.module.sitestat.service.SitestatService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -39,6 +42,8 @@ public class SitestatController extends BaseCRUDJsonBodyMappingController<Sitest @Autowired private IAuthTokenService authTokenService; + @Autowired + private DeviceService deviceService; @Autowired @@ -148,4 +153,7 @@ public class SitestatController extends BaseCRUDJsonBodyMappingController<Sitest return jsonObject.toJSONString(); } + + + } \ No newline at end of file