新闻采集修改,完成发送邮件

This commit is contained in:
2025-11-18 17:56:10 +08:00
parent 049b6f2cf3
commit 9f3176194b
50 changed files with 3929 additions and 322 deletions

View File

@@ -2,6 +2,8 @@ package org.xyzh.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.xyzh.common.core.page.PageParam;
import org.xyzh.common.dto.system.TbSysConfig;
import java.util.List;
@@ -16,12 +18,55 @@ import java.util.List;
@Mapper
public interface SysConfigMapper extends BaseMapper<TbSysConfig> {
/**
* @description 插入系统配置
*/
int insertSysConfig(@Param("config") TbSysConfig config);
/**
* @description 更新系统配置
*/
int updateSysConfig(@Param("config") TbSysConfig config);
/**
* @description 删除系统配置(逻辑删除)
*/
int deleteSysConfig(@Param("id") String id);
/**
* @description 根据配置键查询
*/
TbSysConfig selectSysConfigByKey(@Param("configKey") String configKey);
/**
* @description 根据ID查询
*/
TbSysConfig selectSysConfigById(@Param("id") String id);
/**
* @description 查询所有系统配置
*/
List<TbSysConfig> selectAllSysConfig();
/**
* @description 根据分组查询系统配置
*/
List<TbSysConfig> selectSysConfigByGroup(@Param("configGroup") String configGroup);
/**
* @description 查询系统配置列表
* @param filter 过滤条件
* @return List<TbSysConfig> 系统配置列表
* @author yslg
* @since 2025-10-15
*/
List<TbSysConfig> selectSysConfigs(TbSysConfig filter);
List<TbSysConfig> selectSysConfigs(@Param("filter") TbSysConfig filter);
/**
* @description 分页查询系统配置
*/
List<TbSysConfig> selectSysConfigPage(@Param("filter") TbSysConfig filter, @Param("pageParam") PageParam pageParam);
/**
* @description 查询系统配置总数
*/
int countSelectSysConfig(@Param("filter") TbSysConfig filter);
}

View File

@@ -1,13 +1,208 @@
package org.xyzh.system.service.config.impl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xyzh.api.system.config.SysConfigService;
import org.xyzh.common.dto.system.TbSysConfig;
import org.xyzh.system.mapper.SysConfigMapper;
/**
* @description 系统配置服务实现
* @author AI Assistant
* @since 2025-11-18
*/
@Service
public class SysConfigServiceImpl implements SysConfigService{
public class SysConfigServiceImpl implements SysConfigService {
private static final Logger logger = LoggerFactory.getLogger(SysConfigServiceImpl.class);
@Autowired
private SysConfigMapper sysConfigMapper;
/**
* 根据key查询配置
*/
private TbSysConfig getConfigByKey(String key) {
if (key == null || key.isEmpty()) {
return null;
}
return sysConfigMapper.selectSysConfigByKey(key);
}
@Override
public String getSysConfig(String key) {
return null;
public Object getSysConfig(String key) {
try {
TbSysConfig config = getConfigByKey(key);
if (config == null) {
logger.warn("配置项不存在: {}", key);
return null;
}
String configType = config.getConfigType();
String configValue = config.getConfigValue();
if (configValue == null || configValue.isEmpty()) {
return null;
}
// 根据config_type返回对应的类型
if (configType == null || "string".equalsIgnoreCase(configType)) {
return configValue;
} else if ("number".equalsIgnoreCase(configType) || "integer".equalsIgnoreCase(configType)) {
try {
// 尝试解析为Integer如果失败则解析为Long
return Integer.parseInt(configValue);
} catch (NumberFormatException e) {
try {
return Long.parseLong(configValue);
} catch (NumberFormatException ex) {
logger.error("配置项 {} 的值无法转换为数字: {}", key, configValue);
return configValue;
}
}
} else if ("boolean".equalsIgnoreCase(configType)) {
String value = configValue.toLowerCase().trim();
if ("true".equals(value) || "1".equals(value) || "yes".equals(value) || "on".equals(value)) {
return true;
} else if ("false".equals(value) || "0".equals(value) || "no".equals(value) || "off".equals(value)) {
return false;
} else {
logger.warn("配置项 {} 的值无法识别为Boolean: {}", key, value);
return configValue;
}
} else if ("double".equalsIgnoreCase(configType) || "float".equalsIgnoreCase(configType)) {
try {
return Double.parseDouble(configValue);
} catch (NumberFormatException e) {
logger.error("配置项 {} 的值无法转换为Double: {}", key, configValue);
return configValue;
}
} else {
// 未知类型,直接返回字符串
return configValue;
}
} catch (Exception e) {
logger.error("获取配置失败: {}", key, e);
return null;
}
}
@Override
public String getStringConfig(String key) {
try {
TbSysConfig config = getConfigByKey(key);
if (config == null) {
logger.warn("配置项不存在: {}", key);
return null;
}
return config.getConfigValue();
} catch (Exception e) {
logger.error("获取字符串配置失败: {}", key, e);
return null;
}
}
@Override
public Integer getIntConfig(String key) {
try {
TbSysConfig config = getConfigByKey(key);
if (config == null) {
logger.warn("配置项不存在: {}", key);
return null;
}
String value = config.getConfigValue();
if (value == null || value.isEmpty()) {
return null;
}
return Integer.parseInt(value);
} catch (NumberFormatException e) {
logger.error("配置项 {} 的值无法转换为Integer: {}", key, e.getMessage());
return null;
} catch (Exception e) {
logger.error("获取Integer配置失败: {}", key, e);
return null;
}
}
@Override
public Boolean getBooleanConfig(String key) {
try {
TbSysConfig config = getConfigByKey(key);
if (config == null) {
logger.warn("配置项不存在: {}", key);
return null;
}
String value = config.getConfigValue();
if (value == null || value.isEmpty()) {
return null;
}
// 支持多种布尔值表示true/false, 1/0, yes/no, on/off
value = value.toLowerCase().trim();
if ("true".equals(value) || "1".equals(value) || "yes".equals(value) || "on".equals(value)) {
return true;
} else if ("false".equals(value) || "0".equals(value) || "no".equals(value) || "off".equals(value)) {
return false;
} else {
logger.warn("配置项 {} 的值无法识别为Boolean: {}", key, value);
return null;
}
} catch (Exception e) {
logger.error("获取Boolean配置失败: {}", key, e);
return null;
}
}
@Override
public Double getDoubleConfig(String key) {
try {
TbSysConfig config = getConfigByKey(key);
if (config == null) {
logger.warn("配置项不存在: {}", key);
return null;
}
String value = config.getConfigValue();
if (value == null || value.isEmpty()) {
return null;
}
return Double.parseDouble(value);
} catch (NumberFormatException e) {
logger.error("配置项 {} 的值无法转换为Double: {}", key, e.getMessage());
return null;
} catch (Exception e) {
logger.error("获取Double配置失败: {}", key, e);
return null;
}
}
@Override
public Long getLongConfig(String key) {
try {
TbSysConfig config = getConfigByKey(key);
if (config == null) {
logger.warn("配置项不存在: {}", key);
return null;
}
String value = config.getConfigValue();
if (value == null || value.isEmpty()) {
return null;
}
return Long.parseLong(value);
} catch (NumberFormatException e) {
logger.error("配置项 {} 的值无法转换为Long: {}", key, e.getMessage());
return null;
} catch (Exception e) {
logger.error("获取Long配置失败: {}", key, e);
return null;
}
}
}

View File

@@ -2,55 +2,138 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.xyzh.system.mapper.SysConfigMapper">
<!-- 基础结果映射 -->
<!-- 结果映射 -->
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.system.TbSysConfig">
<id column="id" property="id" jdbcType="VARCHAR"/>
<result column="config_key" property="configKey" jdbcType="VARCHAR"/>
<result column="config_value" property="configValue" jdbcType="LONGVARCHAR"/>
<result column="config_type" property="configType" jdbcType="VARCHAR"/>
<result column="config_group" property="configGroup" jdbcType="VARCHAR"/>
<result column="description" property="description" jdbcType="VARCHAR"/>
<result column="is_system" property="isSystem" jdbcType="BOOLEAN"/>
<result column="creator" property="creator" jdbcType="VARCHAR"/>
<result column="updater" property="updater" jdbcType="VARCHAR"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
<result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
<result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
<id column="id" property="ID" />
<result column="config_key" property="configKey" />
<result column="config_value" property="configValue" />
<result column="config_type" property="configType" />
<result column="config_group" property="configGroup" />
<result column="description" property="description" />
<result column="is_system" property="isSystem" />
<result column="creator" property="creator" />
<result column="updater" property="updater" />
<result column="create_time" property="createTime" />
<result column="update_time" property="updateTime" />
<result column="delete_time" property="deleteTime" />
<result column="deleted" property="deleted" />
</resultMap>
<!-- 基础字段 -->
<!-- 字段列表 -->
<sql id="Base_Column_List">
id, config_key, config_value, config_type, config_group, description,
is_system, creator, updater, create_time, update_time, delete_time, deleted
</sql>
<!-- 通用条件 -->
<sql id="Where_Clause">
<!-- 查询条件 -->
<sql id="Base_Where_Clause">
<where>
deleted = 0
<if test="configKey != null and configKey != ''">
AND config_key = #{configKey}
<if test="filter.configKey != null and filter.configKey != ''">
AND config_key = #{filter.configKey}
</if>
<if test="configGroup != null and configGroup != ''">
AND config_group = #{configGroup}
<if test="filter.configGroup != null and filter.configGroup != ''">
AND config_group = #{filter.configGroup}
</if>
<if test="configType != null and configType != ''">
AND config_type = #{configType}
<if test="filter.configType != null and filter.configType != ''">
AND config_type = #{filter.configType}
</if>
<if test="isSystem != null">
AND is_system = #{isSystem}
<if test="filter.isSystem != null">
AND is_system = #{filter.isSystem}
</if>
</where>
</sql>
<!-- selectSysConfigs -->
<select id="selectSysConfigs" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
<!-- 插入系统配置 -->
<insert id="insertSysConfig" parameterType="org.xyzh.common.dto.system.TbSysConfig">
INSERT INTO tb_sys_config (
id, config_key, config_value, config_type, config_group, description,
is_system, creator, create_time
) VALUES (
#{config.ID}, #{config.configKey}, #{config.configValue}, #{config.configType},
#{config.configGroup}, #{config.description}, #{config.isSystem},
#{config.creator}, NOW()
)
</insert>
<!-- 更新系统配置 -->
<update id="updateSysConfig" parameterType="org.xyzh.common.dto.system.TbSysConfig">
UPDATE tb_sys_config
SET config_value = #{config.configValue},
config_type = #{config.configType},
config_group = #{config.configGroup},
description = #{config.description},
is_system = #{config.isSystem},
updater = #{config.updater},
update_time = NOW()
WHERE id = #{config.ID}
AND deleted = 0
</update>
<!-- 删除系统配置(逻辑删除) -->
<update id="deleteSysConfig">
UPDATE tb_sys_config
SET deleted = 1,
delete_time = NOW()
WHERE id = #{id}
AND deleted = 0
</update>
<!-- 根据配置键查询 -->
<select id="selectSysConfigByKey" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" />
FROM tb_sys_config
<include refid="Where_Clause"/>
WHERE config_key = #{configKey}
AND deleted = 0
</select>
<!-- 根据ID查询 -->
<select id="selectSysConfigById" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" />
FROM tb_sys_config
WHERE id = #{id}
AND deleted = 0
</select>
<!-- 查询所有系统配置 -->
<select id="selectAllSysConfig" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" />
FROM tb_sys_config
WHERE deleted = 0
ORDER BY config_group, config_key
</select>
<!-- 根据分组查询 -->
<select id="selectSysConfigByGroup" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" />
FROM tb_sys_config
WHERE config_group = #{configGroup}
AND deleted = 0
ORDER BY config_key
</select>
<!-- 查询系统配置列表 -->
<select id="selectSysConfigs" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" />
FROM tb_sys_config
<include refid="Base_Where_Clause" />
ORDER BY config_group, config_key
</select>
<!-- 分页查询 -->
<select id="selectSysConfigPage" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" />
FROM tb_sys_config
<include refid="Base_Where_Clause" />
ORDER BY config_group, config_key
LIMIT #{pageParam.offset}, #{pageParam.pageSize}
</select>
<!-- 查询总数 -->
<select id="countSelectSysConfig" resultType="int">
SELECT COUNT(*)
FROM tb_sys_config
<include refid="Base_Where_Clause" />
</select>
</mapper>