package com.hr.controller; import com.github.pagehelper.PageInfo; import com.hr.param.AccountInterfaceParam; import com.hr.param.InterfaceConfigParam; import com.hr.param.IpInterfaceParam; import com.hr.param.SwitchStatusParam; import com.hr.service.IpTokenInterfaceService; import com.hr.service.IpInterfaceService; import com.hr.vo.*; 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.List; /** * 接口管理 * @author : longhoo * @date : 2025-10-10 */ @RestController @RequestMapping("/ipInterface") @Tag(name = "接口管理") public class IpInterfaceController { @Autowired private IpInterfaceService ipInterfaceService; @Autowired private IpTokenInterfaceService ipTokenInterfaceService; /** * 分页查询 * * @param ipInterfaceParam 筛选条件 * @return 查询结果 */ @Operation(summary = "分页查询") @GetMapping("/list") public BasePageResult paginQuery(IpInterfaceParam ipInterfaceParam){ BasePageResult ipAccountPOS = ipInterfaceService.paginQuery(ipInterfaceParam, ipInterfaceParam.getPageNum(), ipInterfaceParam.getPageSize()); return ipAccountPOS; } /** * 新增数据 * * @param ipInterfaceParam 实例对象 * @return 实例对象 */ @Operation(summary = "新增/更新数据") @PostMapping("/saveOrUpdate") public BaseReturnDto saveOrUpdate(@RequestBody IpInterfaceParam ipInterfaceParam){ LoginUser user= TokenUtil.getUser(); ipInterfaceService.saveOrUpdate(ipInterfaceParam,user.getUsername(),user.getUserid()); return BaseReturnDto.success(); } /** * 通过主键删除数据 * * @param id 主键 * @return 是否成功 */ @Operation(summary = "通过主键删除数据") @DeleteMapping("/delete/{id}") public BaseReturnDto deleteById(@PathVariable Long id){ return BaseReturnDto.success(ipInterfaceService.deleteById(id)); } /** * 修改状态 * @param switchStatusParam 主键 * @return 是否成功 */ @Operation(summary = "修改状态") @PostMapping("/switchStatus") public BaseReturnDto switchStatus(@RequestBody SwitchStatusParam switchStatusParam){ return BaseReturnDto.success(ipInterfaceService.switchStatus(switchStatusParam)); } /** * 接口下拉列表 * @return 列表 */ @Operation(summary = "接口下拉列表") @PostMapping("/optionList") public BaseReturnDto> 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 generateToken(){ SecretVO vo = new SecretVO(); String secret = RandomStringUtils.random(64, "0123456789abcdef"); String token = RandomStringUtils.random(32, "0123456789abcdef"); vo.setToken(token); vo.setSecret(secret); return BaseReturnDto.success(vo); } /** * 删除账号接口配置 */ @Operation(summary = "删除账号关联的接口") @DeleteMapping("/delAccountInterface/{id}") public BaseReturnDto delAccountInterface(@PathVariable Long id){ LoginUser user = TokenUtil.getUser(); ipTokenInterfaceService.delAccountInterface(id,user); return BaseReturnDto.success(); } /** * 查询账号下关联的接口列表 */ @Operation(summary = "查询账号下关联的接口列表") @PostMapping("/account/ref/list") public BasePageResult accountInterfaceList(@RequestBody AccountInterfaceParam pageParam){ BasePageResult result = ipTokenInterfaceService.accountInterfaceList(pageParam); return result; } /** * 账号关联接口修改接口状态 * @param switchStatusParam 主键 * @return 是否成功 */ @Operation(summary = "修改状态") @PostMapping("/account/interface/ref/switchStatus") public BaseReturnDto accountInterfaceRefSwitch(@RequestBody SwitchStatusParam switchStatusParam){ return BaseReturnDto.success(ipTokenInterfaceService.switchStatus(switchStatusParam)); } }