10 changed files with 291 additions and 16 deletions
-
35sql/demo.sql
-
27src/main/java/com/qyft/gd/common/constant/SysSettings.java
-
49src/main/java/com/qyft/gd/controller/SysSettingsController.java
-
29src/main/java/com/qyft/gd/mapper/SysSettingsMapper.java
-
12src/main/java/com/qyft/gd/model/dto/SysSettingsDTO.java
-
43src/main/java/com/qyft/gd/model/entity/SysSettings.java
-
14src/main/java/com/qyft/gd/model/vo/SysSettingResult.java
-
29src/main/java/com/qyft/gd/model/vo/SysSettingVO.java
-
49src/main/java/com/qyft/gd/service/impl/SysSettingsServiceImpl.java
-
20src/main/resources/mapper/SysSettingsMapper.xml
@ -0,0 +1,27 @@ |
|||
package com.qyft.gd.common.constant; |
|||
|
|||
/** |
|||
* 操作指令 |
|||
*/ |
|||
public class SysSettings { |
|||
/** |
|||
* 加热区域 |
|||
*/ |
|||
public static final String HEAT_AREA = "heat_area"; |
|||
|
|||
/** |
|||
* 加液区域 |
|||
*/ |
|||
public static final String SOLUTION_AREA = "solution_area"; |
|||
|
|||
/** |
|||
* 拍子区域 |
|||
*/ |
|||
public static final String LID_AREA = "lid_area"; |
|||
|
|||
/** |
|||
* 其他系统配置 |
|||
*/ |
|||
public static final String SYS_SETTING = "sys_setting"; |
|||
|
|||
} |
@ -0,0 +1,49 @@ |
|||
package com.qyft.gd.controller; |
|||
|
|||
import com.qyft.gd.model.dto.SysSettingsDTO; |
|||
import com.qyft.gd.service.SysSettingsService; |
|||
import com.qyft.gd.system.common.result.Result; |
|||
import io.micrometer.common.lang.Nullable; |
|||
import io.swagger.v3.oas.annotations.Operation; |
|||
import io.swagger.v3.oas.annotations.Parameter; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Tag(name = "系统配置") |
|||
@RestController |
|||
@RequestMapping("/api/sys") |
|||
@RequiredArgsConstructor |
|||
@Slf4j |
|||
public class SysSettingsController { |
|||
private final SysSettingsService sysSettingsService; |
|||
@Operation(summary = "获取配置") |
|||
@GetMapping("/getConfig") |
|||
public Result<List<?>> getConfig( |
|||
@Parameter( |
|||
description = "配置类型(heat_area 工作区配置 solution_area 加液区配置 lid_area 拍子区域配置 sys_setting 其他系统配置)" |
|||
) |
|||
@RequestParam |
|||
@Nullable |
|||
String type |
|||
) { |
|||
if (type == null) { |
|||
return Result.success(sysSettingsService.getAllConfig()); |
|||
}else { |
|||
return Result.success(sysSettingsService.getConfig(type)); |
|||
} |
|||
} |
|||
|
|||
@Operation(summary = "更新配置") |
|||
@PutMapping("/updateConfig") |
|||
public Result<String> updateConfig(@RequestBody List<SysSettingsDTO> dto) { |
|||
boolean isSuccess = sysSettingsService.updateConfig(dto); |
|||
if (isSuccess) { |
|||
return Result.success(); |
|||
} |
|||
return Result.failed(); |
|||
} |
|||
} |
@ -0,0 +1,29 @@ |
|||
package com.qyft.gd.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.qyft.gd.model.dto.SysSettingsDTO; |
|||
import com.qyft.gd.model.entity.SysSettings; |
|||
import com.qyft.gd.model.vo.SysSettingVO; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
import java.util.List; |
|||
|
|||
|
|||
/** |
|||
* <p> |
|||
* Mapper 接口 |
|||
* </p> |
|||
* |
|||
* @author 郭安鹏 |
|||
* @since 2025-02-17 |
|||
*/ |
|||
|
|||
@Mapper |
|||
public interface SysSettingsMapper extends BaseMapper<SysSettings> { |
|||
List<SysSettingVO> getConfig(String type); |
|||
|
|||
Boolean updateBatch(List<SysSettingsDTO> dto); |
|||
|
|||
int getIdByCode(String type); |
|||
} |
|||
|
@ -0,0 +1,12 @@ |
|||
package com.qyft.gd.model.dto; |
|||
|
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class SysSettingsDTO { |
|||
@Schema(description = "主键id") |
|||
private Long id; |
|||
@Schema(description = "值") |
|||
private String value; |
|||
} |
@ -0,0 +1,43 @@ |
|||
package com.qyft.gd.model.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
/** |
|||
* <p> |
|||
* 系统配置 |
|||
* </p> |
|||
* |
|||
* @author 郭安鹏 |
|||
* @since 2025-02-17 |
|||
*/ |
|||
@EqualsAndHashCode(callSuper = false) |
|||
@Schema(description = "系统配置") |
|||
@TableName("sys_settings") |
|||
@Data |
|||
public class SysSettings { |
|||
|
|||
@Schema(description = "主键id") |
|||
private Long id; |
|||
|
|||
@Schema(description = "父id") |
|||
private Long parentId; |
|||
|
|||
@Schema(description = "名称") |
|||
private String name; |
|||
|
|||
@Schema(description = "code") |
|||
private String code; |
|||
|
|||
@Schema(description = "配置值") |
|||
private String value1; |
|||
|
|||
@Schema(description = "配置值") |
|||
private String value2; |
|||
|
|||
@Schema(description = "配置值") |
|||
private String value3; |
|||
|
|||
} |
@ -0,0 +1,14 @@ |
|||
package com.qyft.gd.model.vo; |
|||
|
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
import java.util.List; |
|||
|
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Data |
|||
public class SysSettingResult extends SysSettingVO { |
|||
|
|||
private List<SysSettingVO> children; |
|||
|
|||
} |
@ -0,0 +1,29 @@ |
|||
package com.qyft.gd.model.vo; |
|||
|
|||
import com.qyft.gd.model.entity.SysSettings; |
|||
import io.swagger.v3.oas.annotations.media.Schema; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
import java.util.List; |
|||
|
|||
@EqualsAndHashCode(callSuper = false) |
|||
@Data |
|||
public class SysSettingVO { |
|||
|
|||
@Schema(description = "主键id") |
|||
private Long id; |
|||
|
|||
@Schema(description = "父id") |
|||
private Long parentId; |
|||
|
|||
@Schema(description = "名称") |
|||
private String name; |
|||
|
|||
@Schema(description = "code") |
|||
private String code; |
|||
|
|||
@Schema(description = "配置值") |
|||
private String value; |
|||
|
|||
} |
@ -0,0 +1,49 @@ |
|||
package com.qyft.gd.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import com.qyft.gd.mapper.SysSettingsMapper; |
|||
import com.qyft.gd.model.dto.SysSettingsDTO; |
|||
import com.qyft.gd.model.entity.SysSettings; |
|||
import com.qyft.gd.model.vo.SysSettingResult; |
|||
import com.qyft.gd.model.vo.SysSettingVO; |
|||
import com.qyft.gd.service.SysSettingsService; |
|||
import lombok.RequiredArgsConstructor; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 角色业务实现类 |
|||
*/ |
|||
@Service |
|||
@RequiredArgsConstructor |
|||
public class SysSettingsServiceImpl extends ServiceImpl<SysSettingsMapper, SysSettings> implements SysSettingsService { |
|||
private final SysSettingsMapper sysSettingsMapper; |
|||
@Override |
|||
public List<SysSettingVO> getConfig(String type) { |
|||
int parentId = sysSettingsMapper.getIdByCode(type); |
|||
return sysSettingsMapper.getConfig(String.valueOf(parentId)); |
|||
} |
|||
|
|||
@Override |
|||
public List<SysSettingResult> getAllConfig() { |
|||
List<SysSettingVO> list = sysSettingsMapper.getConfig("-1"); |
|||
List<SysSettingResult> result = new ArrayList<>(); |
|||
for (SysSettingVO sysSettings : list) { |
|||
List<SysSettingVO> childrenList = sysSettingsMapper.getConfig(String.valueOf(sysSettings.getId())); |
|||
SysSettingResult map = new SysSettingResult(); |
|||
map.setName(sysSettings.getName()); |
|||
map.setCode(sysSettings.getCode()); |
|||
map.setId(sysSettings.getId()); |
|||
map.setChildren(childrenList); |
|||
result.add(map); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
@Override |
|||
public Boolean updateConfig(List<SysSettingsDTO> dto) { |
|||
return sysSettingsMapper.updateBatch(dto); |
|||
} |
|||
} |
@ -0,0 +1,20 @@ |
|||
<?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.qyft.gd.mapper.SysSettingsMapper"> |
|||
<select id="getConfig" resultType="com.qyft.gd.model.vo.SysSettingVO"> |
|||
select id, parent_id, code, name, value1 as value from sys_settings where parent_id = #{parentId} |
|||
</select> |
|||
<select id="getIdByCode" resultType="java.lang.Integer"> |
|||
select id from sys_settings where code = #{type} |
|||
</select> |
|||
|
|||
<update id="updateBatch" parameterType="java.util.List"> |
|||
<foreach collection="list" item="item" index="index" separator=""> |
|||
UPDATE sys_settings |
|||
SET value1 = #{item.value, jdbcType=VARCHAR} |
|||
WHERE id = #{item.id, jdbcType=BIGINT} |
|||
</foreach> |
|||
</update> |
|||
|
|||
|
|||
</mapper> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue