网络设置
This commit is contained in:
parent
ebeb51ea9b
commit
c95a584357
|
|
@ -20,7 +20,7 @@ public class BonusApplication
|
|||
{
|
||||
// System.setProperty("spring.devtools.restart.enabled", "false");
|
||||
SpringApplication.run(BonusApplication.class, args);
|
||||
System.out.println("(♥◠‿◠)ノ゙ 人工智能平台启动成功 ლ(´ڡ`ლ)゙ \n" +
|
||||
System.out.println("(♥◠‿◠)ノ゙ 车辆道路计数仪系统启动成功 ლ(´ڡ`ლ)゙ \n" +
|
||||
" .-------. ____ __ \n" +
|
||||
" | _ _ \\ \\ \\ / / \n" +
|
||||
" | ( ' ) | \\ _. / ' \n" +
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
package com.bonus.web.controller.data;
|
||||
|
||||
import com.bonus.common.annotation.RequiresPermissions;
|
||||
import com.bonus.common.annotation.SysLog;
|
||||
import com.bonus.common.core.domain.AjaxResult;
|
||||
import com.bonus.common.domain.data.dto.ParamsDto;
|
||||
import com.bonus.common.domain.data.dto.SettingDto;
|
||||
import com.bonus.common.enums.OperaType;
|
||||
import com.bonus.web.service.data.SettingService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @className:SettingController
|
||||
* @author:cwchen
|
||||
* @date:2025-12-25-9:20
|
||||
* @version:1.0
|
||||
* @description:系统设置-web层
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/data/setting")
|
||||
public class SettingController {
|
||||
|
||||
@Resource(name = "SettingService")
|
||||
private SettingService settingService;
|
||||
|
||||
@ApiOperation(notes = "查询系统设置",value = "查询系统设置")
|
||||
@RequiresPermissions("devops:setting:query")
|
||||
@GetMapping("/getSettingDetail")
|
||||
@SysLog(title = "系统设置", businessType = OperaType.QUERY, logType = 1, module = "设备运维->系统设置", details = "查询系统设置")
|
||||
public AjaxResult getSettingDetail(ParamsDto dto) {
|
||||
return settingService.getSettingDetail(dto);
|
||||
}
|
||||
|
||||
@ApiOperation(notes = "系统时间设置",value = "系统时间设置")
|
||||
@RequiresPermissions("devops:setting:setting")
|
||||
@PostMapping("/settingNTP")
|
||||
@SysLog(title = "系统时间设置", businessType = OperaType.QUERY, logType = 1, module = "设备运维->系统设置", details = "系统时间设置")
|
||||
public AjaxResult settingNTP(@RequestBody SettingDto dto) {
|
||||
return settingService.settingNTP(dto);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
package com.bonus.web.service.data;
|
||||
|
||||
import com.bonus.common.core.domain.AjaxResult;
|
||||
import com.bonus.common.domain.data.dto.ParamsDto;
|
||||
import com.bonus.common.domain.data.dto.SettingDto;
|
||||
import com.bonus.common.domain.data.vo.SettingVo;
|
||||
import com.bonus.common.utils.ValidatorsUtils;
|
||||
import com.bonus.data.service.DISettingService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @className:SettingService
|
||||
* @author:cwchen
|
||||
* @date:2025-12-25-9:20
|
||||
* @version:1.0
|
||||
* @description:系统设置-业务层
|
||||
*/
|
||||
@Service(value = "SettingService")
|
||||
@Slf4j
|
||||
public class SettingService {
|
||||
|
||||
@Resource(name = "DISettingService")
|
||||
private DISettingService diSettingService;
|
||||
|
||||
@Resource(name = "ValidatorsUtils")
|
||||
private ValidatorsUtils validatorsUtils;
|
||||
|
||||
/**
|
||||
* 查询系统设置详情
|
||||
*
|
||||
* @param dto
|
||||
* @return AjaxResult
|
||||
* @author cwchen
|
||||
* @date 2025/12/25 11:23
|
||||
*/
|
||||
public AjaxResult getSettingDetail(ParamsDto dto) {
|
||||
SettingVo vo = null;
|
||||
try {
|
||||
vo = diSettingService.getSettingDetail(dto);
|
||||
} catch (Exception e) {
|
||||
log.error(e.toString(), e);
|
||||
}
|
||||
return AjaxResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统时间设置
|
||||
*
|
||||
* @param dto
|
||||
* @return AjaxResult
|
||||
* @author cwchen
|
||||
* @date 2025/12/25 11:30
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AjaxResult settingNTP(SettingDto dto) {
|
||||
String validResult = null;
|
||||
// 校验数据是否合法
|
||||
if (Objects.equals(dto.getSyncMode(), "1")) {
|
||||
validResult = validatorsUtils.valid(dto, dto.getSystemSettingId() == null ? SettingDto.ADD.class : SettingDto.UPDATE.class);
|
||||
} else {
|
||||
validResult = validatorsUtils.valid(dto, SettingDto.MANUAL.class);
|
||||
}
|
||||
if (StringUtils.isNotBlank(validResult)) {
|
||||
return AjaxResult.error(validResult);
|
||||
}
|
||||
try {
|
||||
if (Objects.equals(dto.getSyncMode(), "1")) {
|
||||
// ntp校时数据保存入库
|
||||
diSettingService.settingNTP(dto);
|
||||
} else {
|
||||
// 手动校时无需入库
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error(e.toString(), e);
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return AjaxResult.error();
|
||||
}
|
||||
return AjaxResult.success();
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import com.bonus.common.domain.data.dto.ParamsDto;
|
|||
import com.bonus.common.domain.data.vo.StorageVo;
|
||||
import com.bonus.common.utils.StorageScanner;
|
||||
import com.bonus.data.service.DIStorageService;
|
||||
import com.bonus.data.service.DISystemInfoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
|
@ -26,6 +27,9 @@ public class StorageService {
|
|||
@Resource(name = "DIStorageService")
|
||||
private DIStorageService diStorageService;
|
||||
|
||||
@Resource(name = "DISystemInfoService")
|
||||
private DISystemInfoService diSystemInfoService;
|
||||
|
||||
/**
|
||||
* 查询数据存储
|
||||
*
|
||||
|
|
@ -44,7 +48,7 @@ public class StorageService {
|
|||
try {
|
||||
diStorageService.saveStorageInfo(totalVo);
|
||||
// 更新设备信息的存储
|
||||
|
||||
diSystemInfoService.updateSystemStorage(totalVo);
|
||||
} catch (Exception e) {
|
||||
log.error(e.toString(), e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,4 +35,7 @@ public class ParamsDto {
|
|||
|
||||
/**告警状态*/
|
||||
private String alarmStatus;
|
||||
|
||||
/**系统设置ID*/
|
||||
private Long systemSettingId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,91 @@
|
|||
package com.bonus.common.domain.data.dto;
|
||||
|
||||
import com.bonus.common.domain.admin.dto.TeamDto;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @className:SettingDto
|
||||
* @author:cwchen
|
||||
* @date:2025-12-25-11:21
|
||||
* @version:1.0
|
||||
* @description:系统设置-dto
|
||||
*/
|
||||
@Data
|
||||
public class SettingDto {
|
||||
|
||||
/**
|
||||
* 系统设置id
|
||||
*/
|
||||
@NotNull(message = "系统设置id不能为空", groups = {UPDATE.class})
|
||||
private Long systemSettingId;
|
||||
|
||||
/**
|
||||
* 系统id
|
||||
*/
|
||||
private Long systemId = 1L;
|
||||
|
||||
/**
|
||||
* 设备当前时间
|
||||
*/
|
||||
private Date deviceCurrentTime;
|
||||
|
||||
/**
|
||||
* 校时模式 1.NTP校时 2.手动校时
|
||||
*/
|
||||
private String syncMode;
|
||||
|
||||
/**
|
||||
* 服务器地址 (支持 IPv4 或 域名)
|
||||
*/
|
||||
@NotBlank(message = "服务器地址不能为空", groups = {ADD.class, UPDATE.class})
|
||||
@Length(max = 255, message = "服务器地址字符长度不能超过255", groups = {ADD.class, UPDATE.class})
|
||||
@Pattern(regexp = "^(?=.{1,255}$)(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$|^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$",
|
||||
message = "服务器地址格式不正确(需为有效IP或域名)", groups = {ADD.class, UPDATE.class})
|
||||
private String serverAddress;
|
||||
|
||||
/**
|
||||
* NTP端口 (1-65535)
|
||||
*/
|
||||
@NotBlank(message = "NTP端口不能为空", groups = {ADD.class, UPDATE.class})
|
||||
// 如果前端传的是 String,用正则校验数字范围
|
||||
@Pattern(regexp = "^([1-9]|[1-9]\\d{1,3}|[1-5]\\d{4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5])$",
|
||||
message = "端口号必须在 1-65535 之间", groups = {ADD.class, UPDATE.class})
|
||||
private String ntpPort;
|
||||
|
||||
/**
|
||||
* 校时时间间隔 单位分钟
|
||||
*/
|
||||
@NotNull(message = "校时时间间隔", groups = {ADD.class, UPDATE.class})
|
||||
private Long syncIntervalTime;
|
||||
|
||||
/**
|
||||
* 设置时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date settingTime;
|
||||
|
||||
/**
|
||||
* 新增条件限制
|
||||
*/
|
||||
public interface ADD {
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改条件限制
|
||||
*/
|
||||
public interface UPDATE {
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动校时条件限制
|
||||
*/
|
||||
public interface MANUAL {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package com.bonus.common.domain.data.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @className:SettingVo
|
||||
* @author:cwchen
|
||||
* @date:2025-12-25-11:21
|
||||
* @version:1.0
|
||||
* @description:系统设置-vo
|
||||
*/
|
||||
@Data
|
||||
public class SettingVo {
|
||||
|
||||
/**
|
||||
* 系统设置id
|
||||
*/
|
||||
private Long systemSettingId;
|
||||
|
||||
/**
|
||||
* 系统id
|
||||
*/
|
||||
private Long systemId;
|
||||
|
||||
/**
|
||||
* 设备当前时间
|
||||
*/
|
||||
private Date deviceCurrentTime;
|
||||
|
||||
/**
|
||||
* 校时模式 1.NTP校时 2.手动校时
|
||||
*/
|
||||
private String syncMode;
|
||||
|
||||
/**
|
||||
* 服务器地址
|
||||
*/
|
||||
private String serverAddress;
|
||||
|
||||
/**
|
||||
* NTP端口
|
||||
*/
|
||||
private String ntpPort;
|
||||
|
||||
/**
|
||||
* 校时时间间隔 单位分钟
|
||||
*/
|
||||
private Long syncIntervalTime;
|
||||
|
||||
/**
|
||||
* 设置时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date settingTime;
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.bonus.data.mapper;
|
||||
|
||||
import com.bonus.common.domain.data.dto.ParamsDto;
|
||||
import com.bonus.common.domain.data.dto.SettingDto;
|
||||
import com.bonus.common.domain.data.vo.SettingVo;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @className:DISettingMapper
|
||||
* @author:cwchen
|
||||
* @date:2025-12-25-9:23
|
||||
* @version:1.0
|
||||
* @description:系统设置-数据层
|
||||
*/
|
||||
@Repository(value = "DISettingMapper")
|
||||
public interface DISettingMapper {
|
||||
|
||||
/**
|
||||
* 查询系统设置详情
|
||||
* @param dto
|
||||
* @return SettingVo
|
||||
* @author cwchen
|
||||
* @date 2025/12/25 11:24
|
||||
*/
|
||||
SettingVo getSettingDetail(ParamsDto dto);
|
||||
|
||||
/**
|
||||
* 系统时间设置
|
||||
* @param dto
|
||||
* @return void
|
||||
* @author cwchen
|
||||
* @date 2025/12/25 13:11
|
||||
*/
|
||||
void settingNTP(SettingDto dto);
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.bonus.data.service;
|
||||
|
||||
import com.bonus.common.domain.data.dto.ParamsDto;
|
||||
import com.bonus.common.domain.data.dto.SettingDto;
|
||||
import com.bonus.common.domain.data.vo.SettingVo;
|
||||
|
||||
/**
|
||||
* @className:DISettingService
|
||||
* @author:cwchen
|
||||
* @date:2025-12-25-9:21
|
||||
* @version:1.0
|
||||
* @description:系统设置-业务层
|
||||
*/
|
||||
public interface DISettingService {
|
||||
/**
|
||||
* 查询系统设置详情
|
||||
* @param dto
|
||||
* @return SettingVo
|
||||
* @author cwchen
|
||||
* @date 2025/12/25 11:24
|
||||
*/
|
||||
SettingVo getSettingDetail(ParamsDto dto);
|
||||
|
||||
/**
|
||||
* 系统时间设置
|
||||
* @param dto
|
||||
* @return void
|
||||
* @author cwchen
|
||||
* @date 2025/12/25 13:10
|
||||
*/
|
||||
void settingNTP(SettingDto dto);
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.bonus.data.service.impl;
|
||||
|
||||
import com.bonus.common.domain.data.dto.ParamsDto;
|
||||
import com.bonus.common.domain.data.dto.SettingDto;
|
||||
import com.bonus.common.domain.data.vo.SettingVo;
|
||||
import com.bonus.data.mapper.DISettingMapper;
|
||||
import com.bonus.data.service.DISettingService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @className:DSettingServiceImpl
|
||||
* @author:cwchen
|
||||
* @date:2025-12-25-9:22
|
||||
* @version:1.0
|
||||
* @description:系统设置-业务逻辑层
|
||||
*/
|
||||
@Service(value = "DISettingService")
|
||||
public class DSettingServiceImpl implements DISettingService {
|
||||
|
||||
@Resource(name = "DISettingMapper")
|
||||
private DISettingMapper diSettingMapper;
|
||||
|
||||
@Override
|
||||
public SettingVo getSettingDetail(ParamsDto dto) {
|
||||
return diSettingMapper.getSettingDetail(dto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void settingNTP(SettingDto dto) {
|
||||
diSettingMapper.settingNTP(dto);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bonus.data.mapper.DISettingMapper">
|
||||
<!--系统时间设置-->
|
||||
<insert id="settingNTP">
|
||||
<if test="systemSettingId == null">
|
||||
INSERT INTO tb_system_setting
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="systemId != null">system_id,</if>
|
||||
<if test="syncMode != null and syncMode!=''">sync_mode,</if>
|
||||
<if test="serverAddress != null and serverAddress!=''">server_address,</if>
|
||||
<if test="ntpPort != null and ntpPort!=''">ntp_port,</if>
|
||||
<if test="syncIntervalTime != null and syncIntervalTime!=''">sync_interval_time,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="systemId != null">#{systemId},</if>
|
||||
<if test="syncMode != null and syncMode!=''">#{syncMode},</if>
|
||||
<if test="serverAddress != null and serverAddress!=''">#{serverAddress},</if>
|
||||
<if test="ntpPort != null and ntpPort!=''">#{ntpPort},</if>
|
||||
<if test="syncIntervalTime != null and syncIntervalTime!=''">#{syncIntervalTime},</if>
|
||||
</trim>
|
||||
</if>
|
||||
<if test="systemSettingId != null">
|
||||
UPDATE tb_system_setting
|
||||
SET
|
||||
server_address = #{serverAddress},
|
||||
ntp_port = #{ntpPort},
|
||||
sync_interval_time = #{syncIntervalTime}
|
||||
WHERE system_setting_id = #{systemSettingId};
|
||||
</if>
|
||||
</insert>
|
||||
<!--查询系统设置详情-->
|
||||
<select id="getSettingDetail" resultType="com.bonus.common.domain.data.vo.SettingVo">
|
||||
SELECT system_setting_id AS systemSettingId,
|
||||
device_current_time AS deviceCurrentTime,
|
||||
server_address AS serverAddress,
|
||||
ntp_port AS ntpPort,
|
||||
sync_interval_time AS syncIntervalTime
|
||||
FROM tb_system_setting
|
||||
WHERE system_setting_id = #{systemSettingId} AND sync_mode = '1'
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue