字典配置
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -218,6 +218,11 @@
|
||||
<artifactId>client</artifactId>
|
||||
<version>1.12.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.felord</groupId>
|
||||
<artifactId>wecom-sdk</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
|
||||
116
src/main/java/com/rj/controller/DictItemController.java
Normal file
116
src/main/java/com/rj/controller/DictItemController.java
Normal file
@@ -0,0 +1,116 @@
|
||||
package com.rj.controller;
|
||||
|
||||
import com.rj.dto.QiWeiConfig;
|
||||
import com.rj.entity.DictItem;
|
||||
import com.rj.service.IDictItemService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 字典项/配置项前端控制器
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/dictItem")
|
||||
@Tag(name = "字典项/配置项(dict_item)", description = "增删改查与分页")
|
||||
public class DictItemController {
|
||||
|
||||
@Autowired
|
||||
private IDictItemService dictItemService;
|
||||
|
||||
@PostMapping("/add")
|
||||
@Operation(summary = "新增")
|
||||
public ResponseEntity<Map<String, Object>> add(
|
||||
@Parameter(description = "实体", required = true) @RequestBody DictItem entity) {
|
||||
Map<String, Object> result = dictItemService.add(entity);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新")
|
||||
public ResponseEntity<Map<String, Object>> update(
|
||||
@Parameter(description = "实体", required = true) @RequestBody DictItem entity) {
|
||||
Map<String, Object> result = dictItemService.update(entity);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
@Operation(summary = "删除")
|
||||
public ResponseEntity<Map<String, Object>> delete(
|
||||
@Parameter(description = "主键ID", required = true) @PathVariable String id) {
|
||||
Map<String, Object> result = dictItemService.deleteById(id);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
return ResponseEntity.badRequest().body(result);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "分页查询")
|
||||
public ResponseEntity<Map<String, Object>> list(
|
||||
@RequestParam(defaultValue = "1") Integer current,
|
||||
@RequestParam(defaultValue = "10") Integer size,
|
||||
@RequestParam(required = false) String tenantId,
|
||||
@RequestParam(required = false) String name,
|
||||
@RequestParam(required = false) String type,
|
||||
@RequestParam(required = false) String microService,
|
||||
@RequestParam(required = false) String valueRange) {
|
||||
Map<String, Object> result = dictItemService.pageQuery(current, size, tenantId, name, type, microService, valueRange);
|
||||
Boolean success = (Boolean) result.get("success");
|
||||
if (success != null && success) {
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
return ResponseEntity.internalServerError().body(result);
|
||||
}
|
||||
|
||||
@GetMapping("/get/{id}")
|
||||
@Operation(summary = "按ID查询")
|
||||
public ResponseEntity<Map<String, Object>> getById(
|
||||
@Parameter(description = "主键ID", required = true) @PathVariable String id,
|
||||
@Parameter(description = "名称(可为空)。当 name=qiwei_config 且数据库不存在时,返回默认 QiWeiConfig JSON", required = false)
|
||||
@RequestParam(required = false) String name) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
DictItem data = dictItemService.getById(id);
|
||||
if (data == null) {
|
||||
if ("qiwei_config".equals(name)) {
|
||||
result.put("success", true);
|
||||
result.put("message", "查询成功");
|
||||
result.put("data", new QiWeiConfig());
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
|
||||
result.put("success", false);
|
||||
result.put("message", "记录不存在");
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
result.put("success", true);
|
||||
result.put("message", "查询成功");
|
||||
result.put("data", data);
|
||||
return ResponseEntity.ok(result);
|
||||
} catch (Exception e) {
|
||||
log.error("dict_item get by id error, id={}", id, e);
|
||||
result.put("success", false);
|
||||
result.put("message", "查询异常:" + e.getMessage());
|
||||
return ResponseEntity.internalServerError().body(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
src/main/java/com/rj/dto/QiWeiConfig.java
Normal file
12
src/main/java/com/rj/dto/QiWeiConfig.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.rj.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class QiWeiConfig {
|
||||
|
||||
private String corpid;
|
||||
private String appSecret;
|
||||
private String contractSecret;
|
||||
|
||||
}
|
||||
72
src/main/java/com/rj/entity/DictItem.java
Normal file
72
src/main/java/com/rj/entity/DictItem.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package com.rj.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 字典项/配置项(表 dict_item)
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("dict_item")
|
||||
@Schema(description = "字典项/配置项(dict_item)")
|
||||
public class DictItem implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "主键ID(UUID)")
|
||||
@TableId("id")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "租户ID(UUID)")
|
||||
@TableField("tenant_id")
|
||||
private String tenantId;
|
||||
|
||||
@Schema(description = "名称")
|
||||
@TableField("name")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "值")
|
||||
@TableField("value")
|
||||
private String value;
|
||||
|
||||
@Schema(description = "类型")
|
||||
@TableField("type")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "范围/适用范围")
|
||||
@TableField("value_range")
|
||||
private String valueRange;
|
||||
|
||||
@Schema(description = "所属微服务/服务标识")
|
||||
@TableField("micro_service")
|
||||
private String microService;
|
||||
|
||||
@Schema(description = "描述说明")
|
||||
@TableField("description")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "创建人")
|
||||
@TableField("created_by")
|
||||
private String createdBy;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@TableField("created_time")
|
||||
private LocalDateTime createdTime;
|
||||
|
||||
@Schema(description = "更新人")
|
||||
@TableField("updated_by")
|
||||
private String updatedBy;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
@TableField("updated_time")
|
||||
private LocalDateTime updatedTime;
|
||||
}
|
||||
|
||||
13
src/main/java/com/rj/mapper/DictItemMapper.java
Normal file
13
src/main/java/com/rj/mapper/DictItemMapper.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.rj.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.rj.entity.DictItem;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 字典项/配置项表 Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface DictItemMapper extends BaseMapper<DictItem> {
|
||||
}
|
||||
|
||||
27
src/main/java/com/rj/service/IDictItemService.java
Normal file
27
src/main/java/com/rj/service/IDictItemService.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package com.rj.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.rj.entity.DictItem;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 字典项/配置项服务
|
||||
*/
|
||||
public interface IDictItemService extends IService<DictItem> {
|
||||
|
||||
Map<String, Object> add(DictItem entity);
|
||||
|
||||
Map<String, Object> update(DictItem entity);
|
||||
|
||||
Map<String, Object> deleteById(String id);
|
||||
|
||||
Map<String, Object> pageQuery(Integer current,
|
||||
Integer size,
|
||||
String tenantId,
|
||||
String name,
|
||||
String type,
|
||||
String microService,
|
||||
String valueRange);
|
||||
}
|
||||
|
||||
145
src/main/java/com/rj/service/impl/DictItemServiceImpl.java
Normal file
145
src/main/java/com/rj/service/impl/DictItemServiceImpl.java
Normal file
@@ -0,0 +1,145 @@
|
||||
package com.rj.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rj.entity.DictItem;
|
||||
import com.rj.mapper.DictItemMapper;
|
||||
import com.rj.service.IDictItemService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 字典项/配置项服务实现
|
||||
*/
|
||||
@Service
|
||||
public class DictItemServiceImpl extends ServiceImpl<DictItemMapper, DictItem> implements IDictItemService {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> add(DictItem entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (entity.getTenantId() == null || entity.getTenantId().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "tenantId不能为空");
|
||||
return result;
|
||||
}
|
||||
if (entity.getName() == null || entity.getName().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "name不能为空");
|
||||
return result;
|
||||
}
|
||||
entity.setId(UUID.randomUUID().toString().replace("-", ""));
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
entity.setCreatedTime(now);
|
||||
entity.setUpdatedTime(now);
|
||||
boolean ok = this.save(entity);
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "添加成功" : "添加失败");
|
||||
if (ok) {
|
||||
result.put("data", entity);
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "添加异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> update(DictItem entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (entity.getId() == null || entity.getId().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "ID不能为空");
|
||||
return result;
|
||||
}
|
||||
entity.setUpdatedTime(LocalDateTime.now());
|
||||
boolean ok = this.updateById(entity);
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "更新成功" : "更新失败");
|
||||
if (ok) {
|
||||
result.put("data", this.getById(entity.getId()));
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "更新异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> deleteById(String id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
boolean ok = this.removeById(id);
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "删除成功" : "删除失败");
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "删除异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> pageQuery(Integer current,
|
||||
Integer size,
|
||||
String tenantId,
|
||||
String name,
|
||||
String type,
|
||||
String microService,
|
||||
String valueRange) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (current == null || current < 1) {
|
||||
current = 1;
|
||||
}
|
||||
if (size == null || size < 1) {
|
||||
size = 10;
|
||||
}
|
||||
|
||||
Page<DictItem> page = new Page<>(current, size);
|
||||
LambdaQueryWrapper<DictItem> q = new LambdaQueryWrapper<>();
|
||||
if (tenantId != null && !tenantId.trim().isEmpty()) {
|
||||
q.eq(DictItem::getTenantId, tenantId.trim());
|
||||
}
|
||||
if (name != null && !name.trim().isEmpty()) {
|
||||
q.like(DictItem::getName, name.trim());
|
||||
}
|
||||
if (type != null && !type.trim().isEmpty()) {
|
||||
q.eq(DictItem::getType, type.trim());
|
||||
}
|
||||
if (microService != null && !microService.trim().isEmpty()) {
|
||||
q.eq(DictItem::getMicroService, microService.trim());
|
||||
}
|
||||
if (valueRange != null && !valueRange.trim().isEmpty()) {
|
||||
q.eq(DictItem::getValueRange, valueRange.trim());
|
||||
}
|
||||
q.orderByDesc(DictItem::getUpdatedTime).orderByDesc(DictItem::getCreatedTime);
|
||||
|
||||
Page<DictItem> data = this.page(page, q);
|
||||
result.put("success", true);
|
||||
result.put("message", "查询成功");
|
||||
result.put("data", data.getRecords());
|
||||
result.put("total", data.getTotal());
|
||||
result.put("current", data.getCurrent());
|
||||
result.put("size", data.getSize());
|
||||
result.put("pages", data.getPages());
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
result.put("success", false);
|
||||
result.put("message", "查询异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,3 +282,7 @@ siliconflow:
|
||||
timeout: 30000
|
||||
# 是否启用SiliconFlow服务
|
||||
enabled: true
|
||||
#qiwei:
|
||||
# corpid: wwf863be906c659801
|
||||
# app-secret: 5fiJNav_GrLBN70aBjJK3khRpzDPKoj-b9JhXFwNZOk
|
||||
# contract-secret: KQbOvEW8SQORCkvArJ6aF-voarpveVHN5Jj1p4DnWto
|
||||
Reference in New Issue
Block a user