diff --git a/pom.xml b/pom.xml index 9ec48a6..e58423d 100644 --- a/pom.xml +++ b/pom.xml @@ -218,6 +218,11 @@ client 1.12.0 + + cn.felord + wecom-sdk + 1.3.2 + diff --git a/src/main/java/com/rj/controller/DictItemController.java b/src/main/java/com/rj/controller/DictItemController.java new file mode 100644 index 0000000..79b4d2d --- /dev/null +++ b/src/main/java/com/rj/controller/DictItemController.java @@ -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> add( + @Parameter(description = "实体", required = true) @RequestBody DictItem entity) { + Map 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> update( + @Parameter(description = "实体", required = true) @RequestBody DictItem entity) { + Map 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> delete( + @Parameter(description = "主键ID", required = true) @PathVariable String id) { + Map 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> 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 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> getById( + @Parameter(description = "主键ID", required = true) @PathVariable String id, + @Parameter(description = "名称(可为空)。当 name=qiwei_config 且数据库不存在时,返回默认 QiWeiConfig JSON", required = false) + @RequestParam(required = false) String name) { + Map 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); + } + } +} + diff --git a/src/main/java/com/rj/dto/QiWeiConfig.java b/src/main/java/com/rj/dto/QiWeiConfig.java new file mode 100644 index 0000000..0e8cd7b --- /dev/null +++ b/src/main/java/com/rj/dto/QiWeiConfig.java @@ -0,0 +1,12 @@ +package com.rj.dto; + +import lombok.Data; + +@Data +public class QiWeiConfig { + + private String corpid; + private String appSecret; + private String contractSecret; + +} diff --git a/src/main/java/com/rj/entity/DictItem.java b/src/main/java/com/rj/entity/DictItem.java new file mode 100644 index 0000000..db1f316 --- /dev/null +++ b/src/main/java/com/rj/entity/DictItem.java @@ -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; +} + diff --git a/src/main/java/com/rj/mapper/DictItemMapper.java b/src/main/java/com/rj/mapper/DictItemMapper.java new file mode 100644 index 0000000..7c73937 --- /dev/null +++ b/src/main/java/com/rj/mapper/DictItemMapper.java @@ -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 { +} + diff --git a/src/main/java/com/rj/service/IDictItemService.java b/src/main/java/com/rj/service/IDictItemService.java new file mode 100644 index 0000000..a02e93e --- /dev/null +++ b/src/main/java/com/rj/service/IDictItemService.java @@ -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 { + + Map add(DictItem entity); + + Map update(DictItem entity); + + Map deleteById(String id); + + Map pageQuery(Integer current, + Integer size, + String tenantId, + String name, + String type, + String microService, + String valueRange); +} + diff --git a/src/main/java/com/rj/service/impl/DictItemServiceImpl.java b/src/main/java/com/rj/service/impl/DictItemServiceImpl.java new file mode 100644 index 0000000..775a481 --- /dev/null +++ b/src/main/java/com/rj/service/impl/DictItemServiceImpl.java @@ -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 implements IDictItemService { + + @Override + public Map add(DictItem entity) { + Map 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 update(DictItem entity) { + Map 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 deleteById(String id) { + Map 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 pageQuery(Integer current, + Integer size, + String tenantId, + String name, + String type, + String microService, + String valueRange) { + Map result = new HashMap<>(); + try { + if (current == null || current < 1) { + current = 1; + } + if (size == null || size < 1) { + size = 10; + } + + Page page = new Page<>(current, size); + LambdaQueryWrapper 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 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; + } + } +} + diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e921da4..9cd1d10 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -281,4 +281,8 @@ siliconflow: # 请求超时时间(毫秒) timeout: 30000 # 是否启用SiliconFlow服务 - enabled: true \ No newline at end of file + enabled: true +#qiwei: +# corpid: wwf863be906c659801 +# app-secret: 5fiJNav_GrLBN70aBjJK3khRpzDPKoj-b9JhXFwNZOk +# contract-secret: KQbOvEW8SQORCkvArJ6aF-voarpveVHN5Jj1p4DnWto \ No newline at end of file