Parcourir la source

增加接口平台后台菜单接口

longhu il y a 1 mois
Parent
commit
70fb224211

+ 1 - 2
pom.xml

@@ -29,7 +29,6 @@
         <java.version>21</java.version>
     </properties>
 
-
     <repositories>
         <repository>
             <id>aliyun-public</id>
@@ -106,7 +105,6 @@
             <artifactId>spring-boot-starter-data-jpa</artifactId>
         </dependency>
 
-
         <dependency>
             <groupId>com.basedevelop</groupId>
             <artifactId>basedevelop</artifactId>
@@ -115,6 +113,7 @@
 
 
 
+
         <dependency>
             <groupId>org.mybatis.spring.boot</groupId>
             <artifactId>mybatis-spring-boot-starter</artifactId>

+ 58 - 0
src/main/java/com/hr/controller/IpInterfaceController.java

@@ -1,20 +1,28 @@
 package com.hr.controller;
 
+import com.hr.param.InterfaceConfigParam;
 import com.hr.param.IpInterfaceParam;
 import com.hr.param.SwitchStatusParam;
+import com.hr.repository.service.IpTokenInterfaceService;
 import com.hr.service.IpInterfaceService;
 import com.hr.vo.IpAccountVO;
 import com.hr.vo.IpInterfaceVO;
+import com.hr.vo.NameValueVO;
+import com.hr.vo.SecretVO;
 import com.yy.basedevelop.common.data.BasePageResult;
 import com.yy.basedevelop.common.data.BaseReturnDto;
 import com.yy.basedevelop.common.http.config.TokenUtil;
 import com.yy.basedevelop.dto.LoginUser;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
+import org.apache.commons.lang3.RandomStringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.Random;
+import java.util.UUID;
+
 /**
  * 接口管理
  * @author : longhoo
@@ -26,6 +34,8 @@ import org.springframework.web.bind.annotation.*;
 public class IpInterfaceController {
     @Autowired
     private IpInterfaceService ipInterfaceService;
+    @Autowired
+    private IpTokenInterfaceService ipTokenInterfaceService;
     
     /** 
      * 分页查询
@@ -78,4 +88,52 @@ public class IpInterfaceController {
     }
 
 
+    /**
+     * 接口下拉列表
+     * @return 列表
+     */
+    @Operation(summary = "接口下拉列表")
+    @PostMapping("/optionList")
+    public BaseReturnDto<NameValueVO> optionList(){
+        return BaseReturnDto.success(ipInterfaceService.optionList());
+    }
+
+    /**
+     * 账号配置接口
+     */
+    @Operation(summary = "账号配置接口")
+    @PostMapping("/interfaceConfig")
+    public BaseReturnDto interfaceConfig(@RequestBody InterfaceConfigParam param){
+        LoginUser user = TokenUtil.getUser();
+        ipTokenInterfaceService.interfaceConfig(param,user);
+        return BaseReturnDto.success();
+    }
+
+
+    /**
+     * 生成 token
+     */
+    @Operation(summary = "生成 token")
+    @PostMapping("/token/generate")
+    public BaseReturnDto<SecretVO> generateToken(){
+        SecretVO vo = new SecretVO();
+        String secret = RandomStringUtils.random(256, "0123456789abcdef");
+        String token = RandomStringUtils.random(64, "0123456789abcdef");
+        vo.setToken(token);
+        vo.setSecret(secret);
+        return BaseReturnDto.success(vo);
+    }
+
+
+   /**
+     * 删除配置
+     */
+    @Operation(summary = "删除账号关联的接口")
+    @DeleteMapping("/delAccountInterface/{id}")
+    public BaseReturnDto delAccountInterface(@PathVariable Long id){
+        ipTokenInterfaceService.delAccountInterface(id);
+        return BaseReturnDto.success();
+    }
+
+
 }

+ 38 - 0
src/main/java/com/hr/param/InterfaceConfigParam.java

@@ -0,0 +1,38 @@
+package com.hr.param;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+@Data
+public class InterfaceConfigParam {
+
+    @Schema(description = "id")
+    private Long id;
+
+    @Schema(description = "账号 id")
+    private Long accountId;
+
+    @Schema(description = "接口 id")
+    private Long interfaceId;
+
+    @Schema(description = "是否回调")
+    private Boolean callback;
+
+    @Schema(description = "回调地址")
+    private String callbackUrl;
+
+    @Schema(description = "回调次数")
+    private Integer callbackNum;
+
+    @Schema(description = "状态")
+    private String status;
+
+    @Schema(description = "令牌")
+    private String token;
+
+    @Schema(description = "密钥")
+    private String secret;
+
+    @Schema(description = "备注")
+    private String remark;
+}

+ 7 - 5
src/main/java/com/hr/param/IpAccountParam.java

@@ -1,21 +1,23 @@
 package com.hr.param;
 
+import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
  /**
  * 账户表;IpAccount数据表的PO对象
  * @author : longhoo
  * @date : 2025-10-10
- */
+ **/
+
 @Data
 public class IpAccountParam extends PageParam{
-    /** 主键 */
+    @Schema(description = "主键")
     private Long id ;
-    /** 账户编号 */
+    @Schema(description = "账户编号")
     private String accNo ;
-    /** 备注 */
+    @Schema(description = "备注")
     private String remark ;
-    /** 状态,normal 有效,disable 禁用,delete 删除 */
+    @Schema(description = "状态,normal 有效,disable 禁用,delete 删除")
     private String status ;
 
 }

+ 30 - 27
src/main/java/com/hr/param/IpInterfaceParam.java

@@ -1,5 +1,7 @@
 package com.hr.param;
 
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.media.SchemaProperty;
 import jakarta.persistence.Column;
 import jakarta.persistence.Entity;
 import jakarta.persistence.Id;
@@ -10,39 +12,40 @@ import java.io.Serializable;
 import java.time.LocalDateTime;
 import java.util.Date;
 
- /**
+/**
  * 接口表;IpInterface数据表的PO对象
+ *
  * @author : longhoo
  * @date : 2025-10-10
  */
 @Data
 public class IpInterfaceParam extends PageParam {
 
-    /** 主键,; */
-    private Long id ;
-    /** 接口名称,名称唯一,; */
-    private String interfaceName ;
-     /** 接口编号,标号唯一,; */
-     private String interfaceNo ;
-    /** 接口厂商,; */
-    private String manufacturer ;
-    /** 备注,; */
-    private String remark ;
-    /** 状态,normal 有效,disable 禁用,delete 删除,; */
-    private String status ;
-    /** 接口配置,JSON格式的配置文件,存放接口参数,; */
-    private String interfaceConfig ;
-    /** 创建时间,; */
-    private LocalDateTime addTime ;
-    /** 更新时间,; */
-    private LocalDateTime updateTime ;
-    /** 创建人id,; */
-    private Long addUserId ;
-    /** 更新人id,; */
-    private Long updateUserId ;
-    /** 创建人姓名,; */
-    private String addUserName ;
-    /** 更新人姓名,; */
-    private String updateUserName ;
+    @Schema(description = "主键")
+    private Long id;
+    @Schema(description = "接口名称,名称唯一")
+    private String interfaceName;
+    @Schema(description = "接口编号,标号唯一")
+    private String interfaceNo;
+    @Schema(description = "接口厂商")
+    private String manufacturer;
+    @Schema(description = "备注")
+    private String remark;
+    @Schema(description = "状态,normal 有效,disable 禁用,delete 删除")
+    private String status;
+    @Schema(description = "接口配置,JSON格式的配置文件,存放接口参数")
+    private String interfaceConfig;
+    @Schema(description = "创建时间")
+    private LocalDateTime addTime;
+    @Schema(description = "更新时间")
+    private LocalDateTime updateTime;
+    @Schema(description = "创建人id")
+    private Long addUserId;
+    @Schema(description = "更新人id")
+    private Long updateUserId;
+    @Schema(description = "创建人姓名")
+    private String addUserName;
+    @Schema(description = "更新人姓名")
+    private String updateUserName;
 
 }

+ 3 - 0
src/main/java/com/hr/param/PageParam.java

@@ -1,11 +1,14 @@
 package com.hr.param;
 
+import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
 @Data
 public class PageParam {
 
+    @Schema(description = "当前页码")
     private Integer pageNum;
+    @Schema(description = "每页展示条数")
     private Integer pageSize;
 
     public Integer getPageNum(){

+ 3 - 0
src/main/java/com/hr/param/SwitchStatusParam.java

@@ -1,11 +1,14 @@
 package com.hr.param;
 
+import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
 @Data
 public class SwitchStatusParam {
 
+    @Schema(description = "id")
     private Long id;
 
+    @Schema(description = "状态normal 有效,disable 禁用,delete 删除")
     private String status;
 }

+ 6 - 3
src/main/java/com/hr/repository/domain/IpTokenInterfacePO.java

@@ -24,13 +24,16 @@ public class IpTokenInterfacePO implements Serializable,Cloneable{
     private Long id ;
     /** token表主键,; */
     @Column(name = "tid")
-    private String tid ;
+    private Long tid ;
+    /** account表主键,; */
+    @Column(name = "aid")
+    private Long aid ;
     /** 接口表主键,; */
     @Column(name = "iid")
-    private String iid ;
+    private Long iid ;
     /** 是否支持回调,yes支持,no不支持,; */
     @Column(name = "is_callback")
-    private String isCallback ;
+    private Boolean isCallback ;
     /** 回调地址(回调url),回调的url,只有在支持回调时才有,; */
     @Column(name = "callback_url")
     private String callbackUrl ;

+ 0 - 1
src/main/java/com/hr/repository/jpa/IpTokenInterfaceRepository.java

@@ -12,5 +12,4 @@ import java.util.List;
  */
 public interface IpTokenInterfaceRepository extends JpaRepository<IpTokenInterfacePO,Long> {
 
-    IpTokenInterfacePO queryById(Long tiid);
 }

+ 6 - 0
src/main/java/com/hr/repository/service/IpTokenInterfaceService.java

@@ -1,7 +1,9 @@
 package com.hr.repository.service;
 
+import com.hr.param.InterfaceConfigParam;
 import com.hr.repository.domain.IpTokenInterfacePO;
 import com.hr.vo.IpTokenInterfaceVO;
+import com.yy.basedevelop.dto.LoginUser;
 import org.springframework.data.domain.Page;
 
 /**
@@ -49,4 +51,8 @@ public interface IpTokenInterfaceService{
      * @return 是否成功
      */
     boolean deleteById(Long tiid);
+
+    void interfaceConfig(InterfaceConfigParam param, LoginUser user);
+
+    void delAccountInterface(Long id);
 }

+ 73 - 7
src/main/java/com/hr/repository/service/impl/IpTokenInterfaceServiceImpl.java

@@ -1,18 +1,21 @@
 package com.hr.repository.service.impl;
 
-import com.github.pagehelper.PageHelper;
-import com.github.pagehelper.PageInfo;
-import com.hr.repository.domain.IpLogPO;
+import com.hr.param.InterfaceConfigParam;
 import com.hr.repository.domain.IpTokenInterfacePO;
+import com.hr.repository.domain.IpTokenPO;
 import com.hr.repository.jpa.IpTokenInterfaceRepository;
+import com.hr.repository.jpa.IpTokenRepository;
 import com.hr.repository.service.IpTokenInterfaceService;
+import com.hr.util.SnowflakeIdWorker;
 import com.hr.vo.IpTokenInterfaceVO;
+import com.yy.basedevelop.dto.LoginUser;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.*;
 import org.springframework.stereotype.Service;
 
-import java.util.List;
+import java.time.LocalDateTime;
+import java.util.Optional;
 
 /**
  * token与接口关系表;(ip_token_interface)表服务接口实现类
@@ -23,7 +26,11 @@ import java.util.List;
 public class IpTokenInterfaceServiceImpl implements IpTokenInterfaceService {
     @Autowired
     private IpTokenInterfaceRepository ipTokenInterfaceRepository;
-    
+    @Autowired
+    private IpTokenRepository ipTokenRepository;
+    @Autowired
+    private IpTokenInterfaceService ipTokenInterfaceService;
+
     /** 
      * 通过ID查询单条数据 
      *
@@ -31,7 +38,7 @@ public class IpTokenInterfaceServiceImpl implements IpTokenInterfaceService {
      * @return 实例对象
      */
     public IpTokenInterfaceVO queryById(Long tiid){
-        IpTokenInterfacePO ipTokenInterfacePO = ipTokenInterfaceRepository.queryById(tiid);
+        IpTokenInterfacePO ipTokenInterfacePO = ipTokenInterfaceRepository.findById(tiid).get();
         IpTokenInterfaceVO ipTokenInterfaceVO = new IpTokenInterfaceVO();
         if(ipTokenInterfacePO != null){
             BeanUtils.copyProperties(ipTokenInterfacePO, ipTokenInterfaceVO);
@@ -72,7 +79,66 @@ public class IpTokenInterfaceServiceImpl implements IpTokenInterfaceService {
          return result;
      }
 
-     /**
+    @Override
+    public void delAccountInterface(Long id) {
+        Optional<IpTokenInterfacePO> ipTokenInterfacePOOptional = ipTokenInterfaceRepository.findById(id);
+        if(!ipTokenInterfacePOOptional.isPresent()){
+            throw new RuntimeException("参数异常");
+        }
+        IpTokenInterfacePO ipTokenInterfacePO = ipTokenInterfacePOOptional.get();
+        Long tid = ipTokenInterfacePO.getTid();
+        ipTokenInterfaceRepository.deleteById(id);
+        ipTokenRepository.deleteById(tid);
+    }
+
+    @Override
+    public void interfaceConfig(InterfaceConfigParam param, LoginUser user) {
+        String token = param.getToken();
+        Long id = param.getId();
+        LocalDateTime now = LocalDateTime.now();
+        IpTokenInterfacePO ipTokenInterfacePO;
+        IpTokenPO ipTokenPO;
+        if(id != null){
+            ipTokenInterfacePO = ipTokenInterfaceRepository.findById(param.getId()).get();
+            ipTokenPO = ipTokenRepository.findById(ipTokenInterfacePO.getTid()).get();
+            if(ipTokenPO == null){
+                throw new RuntimeException("参数异常");
+            }
+            Optional<IpTokenInterfacePO> optional = ipTokenInterfaceRepository.findById(id);
+            if(!optional.isPresent()){
+                throw new RuntimeException("参数异常");
+            }
+        }else{
+            ipTokenInterfacePO = new IpTokenInterfacePO();
+            ipTokenPO = new IpTokenPO();
+            ipTokenInterfacePO.setAid(param.getAccountId());
+            ipTokenInterfacePO.setIid(param.getInterfaceId());
+            ipTokenInterfacePO.setAddTime(now);
+            ipTokenInterfacePO.setAddUserId(user.getUserid());
+            ipTokenInterfacePO.setAddUserName(user.getUsername());
+            ipTokenInterfacePO.setId(SnowflakeIdWorker.nextId());
+            ipTokenPO.setAddUserId(user.getUserid());
+            ipTokenPO.setAddUserName(user.getUsername());
+            ipTokenPO.setAid(param.getAccountId());
+            ipTokenPO.setId(SnowflakeIdWorker.nextId());
+            ipTokenInterfacePO.setTid(ipTokenPO.getId());
+        }
+        ipTokenPO.setToken(token);
+        ipTokenPO.setUpdateTime(now);
+        ipTokenPO.setTokenStatus(param.getStatus());
+        ipTokenPO.setUpdateUserName(user.getUsername());
+        ipTokenPO.setUpdateUserId(user.getUserid());
+        ipTokenRepository.save(ipTokenPO);
+        ipTokenInterfacePO.setUpdateTime(now);
+        ipTokenInterfacePO.setUpdateUserName(user.getUsername());
+        ipTokenInterfacePO.setUpdateUserId(user.getUserid());
+        ipTokenInterfacePO.setCallbackNum(param.getCallbackNum());
+        ipTokenInterfacePO.setIsCallback(param.getCallback());
+        ipTokenInterfacePO.setCallbackUrl(param.getCallbackUrl());
+        ipTokenInterfaceRepository.save(ipTokenInterfacePO);
+    }
+
+    /**
      * 通过主键删除数据
      *
      * @param tiid 主键

+ 7 - 0
src/main/java/com/hr/service/IpInterfaceService.java

@@ -1,11 +1,15 @@
 package com.hr.service;
 
+import com.hr.param.InterfaceConfigParam;
 import com.hr.param.IpInterfaceParam;
 import com.hr.param.SwitchStatusParam;
 import com.hr.repository.domain.IpInterfacePO;
 import com.hr.vo.IpInterfaceVO;
+import com.hr.vo.NameValueVO;
 import org.springframework.data.domain.Page;
 
+import java.util.List;
+
 /**
  * 接口表;(ip_interface)表服务接口
  * @author : http://www.yonsum.com
@@ -56,4 +60,7 @@ public interface IpInterfaceService{
 
     Boolean switchStatus(SwitchStatusParam switchStatusParam);
 
+    List<NameValueVO> optionList();
+
+    void interfaceConfig(InterfaceConfigParam param);
 }

+ 22 - 0
src/main/java/com/hr/service/impl/IpInterfaceServiceImpl.java

@@ -1,5 +1,6 @@
 package com.hr.service.impl;
 
+import com.hr.param.InterfaceConfigParam;
 import com.hr.param.IpInterfaceParam;
 import com.hr.param.SwitchStatusParam;
 import com.hr.repository.domain.IpInterfacePO;
@@ -7,6 +8,7 @@ import com.hr.repository.jpa.IpInterfaceRepository;
 import com.hr.service.IpInterfaceService;
 import com.hr.util.SnowflakeIdWorker;
 import com.hr.vo.IpInterfaceVO;
+import com.hr.vo.NameValueVO;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.*;
@@ -16,6 +18,7 @@ import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
+import java.util.stream.Collectors;
 
 /**
  * 接口表;(ip_interface)表服务接口实现类
@@ -89,6 +92,25 @@ public class IpInterfaceServiceImpl implements IpInterfaceService {
         ipInterfaceRepository.save(IpInterfacePO);
     }
 
+    @Override
+    public void interfaceConfig(InterfaceConfigParam param) {
+
+    }
+
+    @Override
+    public List<NameValueVO> optionList() {
+        List<IpInterfacePO> list = ipInterfaceRepository.findAll();
+        List<IpInterfacePO> resultList = list.stream().filter(item -> item.getStatus().equals("normal")).collect(Collectors.toList());
+        List<NameValueVO> result = new ArrayList<>();
+        resultList.forEach(item -> {
+            NameValueVO vo = new NameValueVO();
+            vo.setName(item.getInterfaceName());
+            vo.setId(item.getId());
+            result.add(vo);
+        });
+        return result;
+    }
+
     @Override
     public Boolean switchStatus(SwitchStatusParam switchStatusParam) {
         Optional<IpInterfacePO> optional = ipInterfaceRepository.findById(switchStatusParam.getId());

+ 11 - 0
src/main/java/com/hr/vo/NameValueVO.java

@@ -0,0 +1,11 @@
+package com.hr.vo;
+
+import lombok.Data;
+
+@Data
+public class NameValueVO {
+
+    private Long id;
+
+    private String name;
+}

+ 12 - 0
src/main/java/com/hr/vo/SecretVO.java

@@ -0,0 +1,12 @@
+package com.hr.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class SecretVO implements Serializable {
+    private String token;
+
+    private String secret;
+}