package cn.iocoder.yudao.module.mp.controller.admin.account; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.mp.controller.admin.account.vo.*; import cn.iocoder.yudao.module.mp.convert.account.MpAccountConvert; import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO; import cn.iocoder.yudao.module.mp.service.account.MpAccountService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import jakarta.annotation.Resource; import jakarta.validation.Valid; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Tag(name = "管理后台 - 公众号账号") @RestController @RequestMapping("/mp/account") @Validated public class MpAccountController { @Resource private MpAccountService mpAccountService; @PostMapping("/create") @Operation(summary = "创建公众号账号") @PreAuthorize("@ss.hasPermission('mp:account:create')") public CommonResult createAccount(@Valid @RequestBody MpAccountCreateReqVO createReqVO) { return success(mpAccountService.createAccount(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新公众号账号") @PreAuthorize("@ss.hasPermission('mp:account:update')") public CommonResult updateAccount(@Valid @RequestBody MpAccountUpdateReqVO updateReqVO) { mpAccountService.updateAccount(updateReqVO); return success(true); } @DeleteMapping("/delete") @Operation(summary = "删除公众号账号") @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('mp:account:delete')") public CommonResult deleteAccount(@RequestParam("id") Long id) { mpAccountService.deleteAccount(id); return success(true); } @GetMapping("/get") @Operation(summary = "获得公众号账号") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('mp:account:query')") public CommonResult getAccount(@RequestParam("id") Long id) { MpAccountDO wxAccount = mpAccountService.getAccount(id); return success(MpAccountConvert.INSTANCE.convert(wxAccount)); } @GetMapping("/page") @Operation(summary = "获得公众号账号分页") @PreAuthorize("@ss.hasPermission('mp:account:query')") public CommonResult> getAccountPage(@Valid MpAccountPageReqVO pageVO) { PageResult pageResult = mpAccountService.getAccountPage(pageVO); return success(MpAccountConvert.INSTANCE.convertPage(pageResult)); } @GetMapping("/list-all-simple") @Operation(summary = "获取公众号账号精简信息列表") @PreAuthorize("@ss.hasPermission('mp:account:query')") public CommonResult> getSimpleAccounts() { List list = mpAccountService.getAccountList(); return success(MpAccountConvert.INSTANCE.convertList02(list)); } @PutMapping("/generate-qr-code") @Operation(summary = "生成公众号二维码") @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('mp:account:qr-code')") public CommonResult generateAccountQrCode(@RequestParam("id") Long id) { mpAccountService.generateAccountQrCode(id); return success(true); } @PutMapping("/clear-quota") @Operation(summary = "清空公众号 API 配额") @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('mp:account:clear-quota')") public CommonResult clearAccountQuota(@RequestParam("id") Long id) { mpAccountService.clearAccountQuota(id); return success(true); } }