Browse Source

优化设备状态相关内容

develop
zhaoxianglong 5 months ago
parent
commit
e596de5c34
  1. 10
      zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java
  2. 31
      zc-business/src/main/java/com/zc/business/controller/StatusController.java
  3. 1
      zc-business/src/main/java/com/zc/business/mapper/StatusMapper.java
  4. 3
      zc-business/src/main/java/com/zc/business/service/impl/StatusService.java
  5. 10
      zc-business/src/main/resources/mapper/business/StatusMapper.xml

10
zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java

@ -15,6 +15,7 @@ import com.zc.business.service.impl.StatusService;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.BufferedReader; import java.io.BufferedReader;
@ -94,6 +95,15 @@ public class DeviceStatus {
executor.shutdown(); executor.shutdown();
} }
@Scheduled(cron = "0 30 23 * * ?")
//@Scheduled(cron = "0 30 * * * ?")
public void periodicDataClearing() {
StatusService statusService = SpringUtils.getBean(StatusService.class);
LocalDateTime startTime = LocalDateTime.now().minusMonths(UniversalEnum.THREE.getNumber());
Status status = new Status();
status.setStartTime(startTime);
statusService.delStatusByTime(status);
}
private void extracted(StatusService statusService, DcDevice device, boolean reachable, String packetLossRate) { private void extracted(StatusService statusService, DcDevice device, boolean reachable, String packetLossRate) {
Status status = new Status(); Status status = new Status();
status.setDeviceNo(device.getStakeMark()); status.setDeviceNo(device.getStakeMark());

31
zc-business/src/main/java/com/zc/business/controller/StatusController.java

@ -51,13 +51,15 @@ public class StatusController extends BaseController {
//设备列表 //设备列表
@ApiOperation("设备状态列表按时间和类型") @ApiOperation("设备状态列表按时间和类型")
@GetMapping("/tablist") @GetMapping("/tablist")
public TableDataInfo getTabList(Status status) public TableDataInfo getTabList(Status status) {
{
if (status.getDeviceName() != null) { if (status.getDeviceName() != null) {
status.setDeviceName(status.getDeviceName().replaceAll(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.PLUS_SIGN.getValue())); status.setDeviceName(status.getDeviceName().replaceAll(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.PLUS_SIGN.getValue()));
} }
startPage(); startPage();
status.setTypes(status.getType().split(UniversalEnum.COMMA.getValue())); String type = status.getType();
if (type != null) {
status.setTypes(type.split(UniversalEnum.COMMA.getValue()));
}
List<Status> listStatus = statusService.listStatusByTypes(status); List<Status> listStatus = statusService.listStatusByTypes(status);
return getDataTable(listStatus); return getDataTable(listStatus);
} }
@ -69,12 +71,14 @@ public class StatusController extends BaseController {
@ApiOperation("设备状态导出") @ApiOperation("设备状态导出")
@Log(title = "【设备状态导出】", businessType = BusinessType.EXPORT) @Log(title = "【设备状态导出】", businessType = BusinessType.EXPORT)
@PostMapping("/export") @PostMapping("/export")
public void export(HttpServletResponse response, Status status) public void export(HttpServletResponse response, Status status) {
{
if (status.getDeviceName() != null) { if (status.getDeviceName() != null) {
status.setDeviceName(status.getDeviceName().replaceAll(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.PLUS_SIGN.getValue())); status.setDeviceName(status.getDeviceName().replaceAll(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.PLUS_SIGN.getValue()));
} }
status.setTypes(status.getType().split(UniversalEnum.COMMA.getValue())); String type = status.getType();
if (type != null) {
status.setTypes(type.split(UniversalEnum.COMMA.getValue()));
}
List<Status> listStatus = statusService.export(status); List<Status> listStatus = statusService.export(status);
ExcelUtil<Status> util = new ExcelUtil<>(Status.class); ExcelUtil<Status> util = new ExcelUtil<>(Status.class);
util.exportExcel(response, listStatus, UniversalEnum.DEVICE_STATUS_LIST.getValue()); util.exportExcel(response, listStatus, UniversalEnum.DEVICE_STATUS_LIST.getValue());
@ -91,12 +95,18 @@ public class StatusController extends BaseController {
LocalDateTime currentTime = status.getTime().truncatedTo(ChronoUnit.DAYS).plusDays(UniversalEnum.ONE.getNumber()); LocalDateTime currentTime = status.getTime().truncatedTo(ChronoUnit.DAYS).plusDays(UniversalEnum.ONE.getNumber());
status.setStartTime(todayStart); status.setStartTime(todayStart);
status.setTime(currentTime); status.setTime(currentTime);
String[] types = status.getType().split(UniversalEnum.COMMA.getValue()); String statusType = status.getType();
String[] types = null;
if (statusType != null) {
types = statusType.split(UniversalEnum.COMMA.getValue());
status.setTypes(types); status.setTypes(types);
}
Map<String, Map<String, String>> maps = new HashMap<>(); Map<String, Map<String, String>> maps = new HashMap<>();
List<Status> statuses = statusService.getStatusList(status); List<Status> statuses = statusService.getStatusList(status);
if (types != null) {
for (String type : types) { for (String type : types) {
Map<String, String> collect = statuses.stream().filter(item -> Objects.equals(item.getType(), type)) Map<String, String> collect = statuses.stream().filter(item -> Objects.equals(item.getType(), type))
.collect(Collectors.toMap( .collect(Collectors.toMap(
@ -105,6 +115,7 @@ public class StatusController extends BaseController {
)); ));
maps.put(type, collect); maps.put(type, collect);
} }
}
return AjaxResult.success(maps); return AjaxResult.success(maps);
} }
@ -112,8 +123,7 @@ public class StatusController extends BaseController {
//按时间划分设备柱状图 //按时间划分设备柱状图
@ApiOperation("更新缓存规则") @ApiOperation("更新缓存规则")
@GetMapping("/rule") @GetMapping("/rule")
public AjaxResult setRule(String rule) public AjaxResult setRule(String rule) {
{
redisCache.setCacheObject(ORDERRULE, rule); redisCache.setCacheObject(ORDERRULE, rule);
return AjaxResult.success(); return AjaxResult.success();
} }
@ -159,8 +169,7 @@ public class StatusController extends BaseController {
//按类型划分设备 //按类型划分设备
@ApiOperation("设备状态列表按类型") @ApiOperation("设备状态列表按类型")
@GetMapping("/type") @GetMapping("/type")
public AjaxResult getTypeList() public AjaxResult getTypeList() {
{
//DcDevice dcDevice = new DcDevice(); //DcDevice dcDevice = new DcDevice();
//dcDevice.setUseState(1); //dcDevice.setUseState(1);
//List<DcDevice> dcDeviceList = dcDeviceService.numberOfDevicesByType(dcDevice); //List<DcDevice> dcDeviceList = dcDeviceService.numberOfDevicesByType(dcDevice);

1
zc-business/src/main/java/com/zc/business/mapper/StatusMapper.java

@ -25,4 +25,5 @@ public interface StatusMapper {
List<Status> listStatusByTypes(@Param("status")Status status); List<Status> listStatusByTypes(@Param("status")Status status);
List<Status> getStatusList(@Param("status")Status status); List<Status> getStatusList(@Param("status")Status status);
int delStatusByTime(Status status);
} }

3
zc-business/src/main/java/com/zc/business/service/impl/StatusService.java

@ -53,4 +53,7 @@ public class StatusService {
return list; return list;
} }
public int delStatusByTime(Status status) {
return statusMapper.delStatusByTime(status);
}
} }

10
zc-business/src/main/resources/mapper/business/StatusMapper.xml

@ -328,4 +328,14 @@
</if> </if>
</select> </select>
<delete id="delStatusByTime" parameterType="com.zc.business.domain.Status">
DELETE FROM status
<where>
<if test="startTime != null">
AND status.time &lt; #{startTime,jdbcType=DATE}
</if>
</where>
</delete>
</mapper> </mapper>

Loading…
Cancel
Save