11 changed files with 357 additions and 0 deletions
@ -0,0 +1,72 @@ |
|||||
|
package cn.iocoder.yudao.module.system.controller.admin.config.SystemConfig; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
import cn.iocoder.yudao.module.system.controller.admin.config.SystemConfig.vo.*; |
||||
|
import cn.iocoder.yudao.module.system.convert.config.SystemConfigConvert; // 确保引入正确的Convert
|
||||
|
import cn.iocoder.yudao.module.system.dal.dataobject.config.SystemConfigDO; |
||||
|
import cn.iocoder.yudao.module.system.service.config.SystemConfig.SystemConfigService; |
||||
|
import io.swagger.v3.oas.annotations.Operation; |
||||
|
import io.swagger.v3.oas.annotations.Parameter; |
||||
|
import io.swagger.v3.oas.annotations.tags.Tag; |
||||
|
import jakarta.annotation.Resource; |
||||
|
import jakarta.validation.Valid; |
||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||
|
import org.springframework.validation.annotation.Validated; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
|
||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
||||
|
|
||||
|
@Tag(name = "管理后台 - 系统配置") |
||||
|
@RestController |
||||
|
@RequestMapping("/system/system-config") |
||||
|
@Validated |
||||
|
public class SystemConfigController { |
||||
|
|
||||
|
@Resource |
||||
|
private SystemConfigService systemConfigService; |
||||
|
|
||||
|
@Resource |
||||
|
private SystemConfigConvert systemConfigConvert; // 【关键修正】注入Converter
|
||||
|
|
||||
|
@PostMapping("/create") |
||||
|
@Operation(summary = "创建系统配置") |
||||
|
@PreAuthorize("@ss.hasPermission('system:system-config:create')") |
||||
|
public CommonResult<Long> createSystemConfig(@Valid @RequestBody SystemConfigSaveReqVO createReqVO) { |
||||
|
return success(systemConfigService.createSystemConfig(createReqVO)); |
||||
|
} |
||||
|
|
||||
|
@PutMapping("/update") |
||||
|
@Operation(summary = "更新系统配置") |
||||
|
@PreAuthorize("@ss.hasPermission('system:system-config:update')") |
||||
|
public CommonResult<Boolean> updateSystemConfig(@Valid @RequestBody SystemConfigSaveReqVO updateReqVO) { |
||||
|
systemConfigService.updateSystemConfig(updateReqVO); |
||||
|
return success(true); |
||||
|
} |
||||
|
|
||||
|
@DeleteMapping("/delete") |
||||
|
@Operation(summary = "删除系统配置") |
||||
|
@Parameter(name = "id", description = "编号", required = true) |
||||
|
@PreAuthorize("@ss.hasPermission('system:system-config:delete')") |
||||
|
public CommonResult<Boolean> deleteSystemConfig(@RequestParam("id") Long id) { |
||||
|
systemConfigService.deleteSystemConfig(id); |
||||
|
return success(true); |
||||
|
} |
||||
|
|
||||
|
@GetMapping("/get") |
||||
|
@Operation(summary = "获得系统配置") |
||||
|
@Parameter(name = "id", description = "编号", required = true, example = "1024") |
||||
|
@PreAuthorize("@ss.hasPermission('system:system-config:query')") |
||||
|
public CommonResult<SystemConfigRespVO> getSystemConfig(@RequestParam("id") Long id) { |
||||
|
SystemConfigDO config = systemConfigService.getSystemConfig(id); |
||||
|
return success(systemConfigConvert.convert(config)); // 【关键修正】使用注入的bean进行转换
|
||||
|
} |
||||
|
|
||||
|
@GetMapping("/page") |
||||
|
@Operation(summary = "获得系统配置分页") |
||||
|
@PreAuthorize("@ss.hasPermission('system:system-config:query')") |
||||
|
public CommonResult<PageResult<SystemConfigRespVO>> getSystemConfigPage(@Valid SystemConfigPageReqVO pageVO) { |
||||
|
PageResult<SystemConfigDO> pageResult = systemConfigService.getSystemConfigPage(pageVO); |
||||
|
return success(systemConfigConvert.convertPage(pageResult)); // 【关键修正】使用注入的bean进行转换
|
||||
|
} |
||||
|
} |
@ -0,0 +1,15 @@ |
|||||
|
package cn.iocoder.yudao.module.system.controller.admin.config.SystemConfig.vo; |
||||
|
|
||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||
|
import jakarta.validation.constraints.NotBlank; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
@Data |
||||
|
public class SystemConfigBaseVO { |
||||
|
@Schema(description = "系统名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "锅炉系统") |
||||
|
@NotBlank(message = "系统名称不能为空") |
||||
|
private String name; |
||||
|
|
||||
|
@Schema(description = "系统简称", example = "锅炉") |
||||
|
private String abbreviation; |
||||
|
} |
@ -0,0 +1,14 @@ |
|||||
|
package cn.iocoder.yudao.module.system.controller.admin.config.SystemConfig.vo; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam; |
||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
@Schema(description = "管理后台 - 系统配置分页请求 VO") |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
public class SystemConfigPageReqVO extends PageParam { |
||||
|
@Schema(description = "系统名称", example = "锅炉") |
||||
|
private String name; |
||||
|
} |
@ -0,0 +1,13 @@ |
|||||
|
package cn.iocoder.yudao.module.system.controller.admin.config.SystemConfig.vo; |
||||
|
|
||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
@Schema(description = "管理后台 - 系统配置响应 VO") |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
public class SystemConfigRespVO extends SystemConfigBaseVO { |
||||
|
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED) |
||||
|
private Long id; |
||||
|
} |
@ -0,0 +1,13 @@ |
|||||
|
package cn.iocoder.yudao.module.system.controller.admin.config.SystemConfig.vo; |
||||
|
|
||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
@Schema(description = "管理后台 - 系统配置创建/修改 Request VO") |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
public class SystemConfigSaveReqVO extends SystemConfigBaseVO { |
||||
|
@Schema(description = "编号,更新时必填", example = "1") |
||||
|
private Long id; |
||||
|
} |
@ -0,0 +1,48 @@ |
|||||
|
package cn.iocoder.yudao.module.system.convert.config; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
import cn.iocoder.yudao.module.system.controller.admin.config.SystemConfig.vo.SystemConfigRespVO; |
||||
|
import cn.iocoder.yudao.module.system.controller.admin.config.SystemConfig.vo.SystemConfigSaveReqVO; |
||||
|
import cn.iocoder.yudao.module.system.dal.dataobject.config.SystemConfigDO; |
||||
|
import org.mapstruct.Mapper; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Mapper(componentModel = "spring") |
||||
|
public interface SystemConfigConvert { |
||||
|
|
||||
|
default SystemConfigRespVO convert(SystemConfigDO bean) { |
||||
|
if (bean == null) { |
||||
|
return null; |
||||
|
} |
||||
|
SystemConfigRespVO respVO = new SystemConfigRespVO(); |
||||
|
|
||||
|
respVO.setId(bean.getId()); |
||||
|
respVO.setName(bean.getName()); |
||||
|
respVO.setAbbreviation(bean.getAbbreviation()); |
||||
|
|
||||
|
return respVO; |
||||
|
} |
||||
|
|
||||
|
default List<SystemConfigRespVO> convertList(List<SystemConfigDO> list) { |
||||
|
if (list == null) { |
||||
|
return null; |
||||
|
} |
||||
|
List<SystemConfigRespVO> result = new ArrayList<>(list.size()); |
||||
|
for (SystemConfigDO systemConfigDO : list) { |
||||
|
result.add(convert(systemConfigDO)); |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
default PageResult<SystemConfigRespVO> convertPage(PageResult<SystemConfigDO> page) { |
||||
|
if (page == null) { |
||||
|
return null; |
||||
|
} |
||||
|
return new PageResult<>(convertList(page.getList()), page.getTotal()); |
||||
|
} |
||||
|
|
||||
|
SystemConfigDO convert(SystemConfigSaveReqVO bean); |
||||
|
|
||||
|
} |
@ -0,0 +1,35 @@ |
|||||
|
package cn.iocoder.yudao.module.system.dal.dataobject.config; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.TableField; |
||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import lombok.*; |
||||
|
|
||||
|
/** |
||||
|
* 系统配置 DO |
||||
|
* |
||||
|
* @author 芋道源码 |
||||
|
*/ |
||||
|
@TableName("system_cfg") |
||||
|
@Data |
||||
|
@Builder |
||||
|
@NoArgsConstructor |
||||
|
@AllArgsConstructor |
||||
|
public class SystemConfigDO { |
||||
|
|
||||
|
@TableId("system_id") |
||||
|
private Long id; |
||||
|
|
||||
|
@TableField("system_name") |
||||
|
private String name; |
||||
|
|
||||
|
@TableField("system_shortname") |
||||
|
private String abbreviation; |
||||
|
|
||||
|
@TableField("system_type_id") |
||||
|
private Integer systemTypeId; |
||||
|
|
||||
|
@TableField("unit_id") |
||||
|
private Integer unitId; |
||||
|
|
||||
|
} |
@ -0,0 +1,23 @@ |
|||||
|
package cn.iocoder.yudao.module.system.dal.mysql.config; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
||||
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
||||
|
import cn.iocoder.yudao.module.system.controller.admin.config.SystemConfig.vo.SystemConfigPageReqVO; |
||||
|
import cn.iocoder.yudao.module.system.dal.dataobject.config.SystemConfigDO; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
@Mapper |
||||
|
public interface SystemConfigMapper extends BaseMapperX<SystemConfigDO> { |
||||
|
|
||||
|
// 【关键修正】恢复使用框架默认的分页查询,无需XML
|
||||
|
default PageResult<SystemConfigDO> selectPage(SystemConfigPageReqVO reqVO) { |
||||
|
return selectPage(reqVO, new LambdaQueryWrapperX<SystemConfigDO>() |
||||
|
.likeIfPresent(SystemConfigDO::getName, reqVO.getName()) |
||||
|
.orderByDesc(SystemConfigDO::getId)); |
||||
|
} |
||||
|
|
||||
|
default SystemConfigDO selectByName(String name) { |
||||
|
return selectOne(SystemConfigDO::getName, name); |
||||
|
} |
||||
|
} |
@ -0,0 +1,44 @@ |
|||||
|
package cn.iocoder.yudao.module.system.service.config.SystemConfig; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
import cn.iocoder.yudao.module.system.controller.admin.config.SystemConfig.vo.SystemConfigPageReqVO; |
||||
|
import cn.iocoder.yudao.module.system.controller.admin.config.SystemConfig.vo.SystemConfigSaveReqVO; |
||||
|
import cn.iocoder.yudao.module.system.dal.dataobject.config.SystemConfigDO; |
||||
|
import jakarta.validation.Valid; |
||||
|
|
||||
|
public interface SystemConfigService { |
||||
|
|
||||
|
/** |
||||
|
* 创建系统配置 |
||||
|
* @param createReqVO 创建信息 |
||||
|
* @return 编号 |
||||
|
*/ |
||||
|
Long createSystemConfig(@Valid SystemConfigSaveReqVO createReqVO); |
||||
|
|
||||
|
/** |
||||
|
* 更新系统配置 |
||||
|
* @param updateReqVO 更新信息 |
||||
|
*/ |
||||
|
void updateSystemConfig(@Valid SystemConfigSaveReqVO updateReqVO); |
||||
|
|
||||
|
/** |
||||
|
* 删除系统配置 |
||||
|
* @param id 编号 |
||||
|
*/ |
||||
|
void deleteSystemConfig(Long id); |
||||
|
|
||||
|
/** |
||||
|
* 获得系统配置 |
||||
|
* @param id 编号 |
||||
|
* @return 系统配置 |
||||
|
*/ |
||||
|
SystemConfigDO getSystemConfig(Long id); |
||||
|
|
||||
|
/** |
||||
|
* 获得系统配置分页 |
||||
|
* @param pageReqVO 分页查询 |
||||
|
* @return 系统配置分页 |
||||
|
*/ |
||||
|
PageResult<SystemConfigDO> getSystemConfigPage(SystemConfigPageReqVO pageReqVO); |
||||
|
|
||||
|
} |
@ -0,0 +1,75 @@ |
|||||
|
package cn.iocoder.yudao.module.system.service.config.SystemConfig; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; |
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
import cn.iocoder.yudao.module.system.controller.admin.config.SystemConfig.vo.SystemConfigPageReqVO; |
||||
|
import cn.iocoder.yudao.module.system.controller.admin.config.SystemConfig.vo.SystemConfigSaveReqVO; |
||||
|
import cn.iocoder.yudao.module.system.convert.config.SystemConfigConvert; |
||||
|
import cn.iocoder.yudao.module.system.dal.dataobject.config.SystemConfigDO; |
||||
|
import cn.iocoder.yudao.module.system.dal.mysql.config.SystemConfigMapper; |
||||
|
import jakarta.annotation.Resource; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.validation.annotation.Validated; |
||||
|
|
||||
|
import java.util.Objects; |
||||
|
|
||||
|
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; |
||||
|
|
||||
|
@Service |
||||
|
@Validated |
||||
|
public class SystemConfigServiceImpl implements SystemConfigService { |
||||
|
|
||||
|
@Resource |
||||
|
private SystemConfigMapper systemConfigMapper; |
||||
|
|
||||
|
@Resource |
||||
|
private SystemConfigConvert systemConfigConvert; |
||||
|
|
||||
|
@Override |
||||
|
public Long createSystemConfig(SystemConfigSaveReqVO createReqVO) { |
||||
|
validateNameDuplicate(createReqVO.getName(), null); |
||||
|
SystemConfigDO systemConfig = systemConfigConvert.convert(createReqVO); |
||||
|
systemConfigMapper.insert(systemConfig); |
||||
|
return systemConfig.getId(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void updateSystemConfig(SystemConfigSaveReqVO updateReqVO) { |
||||
|
validateExists(updateReqVO.getId()); |
||||
|
validateNameDuplicate(updateReqVO.getName(), updateReqVO.getId()); |
||||
|
SystemConfigDO updateObj = systemConfigConvert.convert(updateReqVO); |
||||
|
systemConfigMapper.updateById(updateObj); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void deleteSystemConfig(Long id) { |
||||
|
validateExists(id); |
||||
|
systemConfigMapper.deleteById(id); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public SystemConfigDO getSystemConfig(Long id) { |
||||
|
return systemConfigMapper.selectById(id); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public PageResult<SystemConfigDO> getSystemConfigPage(SystemConfigPageReqVO pageReqVO) { |
||||
|
return systemConfigMapper.selectPage(pageReqVO); |
||||
|
} |
||||
|
|
||||
|
private void validateExists(Long id) { |
||||
|
if (systemConfigMapper.selectById(id) == null) { |
||||
|
throw ServiceExceptionUtil.exception(SYSTEM_CONFIG_NOT_EXISTS); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void validateNameDuplicate(String name, Long id) { |
||||
|
SystemConfigDO config = systemConfigMapper.selectByName(name); |
||||
|
if (config == null) { |
||||
|
return; |
||||
|
} |
||||
|
if (id == null || !Objects.equals(config.getId(), id)) { |
||||
|
throw ServiceExceptionUtil.exception(SYSTEM_CONFIG_NAME_DUPLICATE); |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue