package com.ruoyi.user.controller; import java.util.List; import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.poi.ExcelUtil; import com.ruoyi.common.core.web.controller.BaseController; import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.page.TableDataInfo; import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.enums.BusinessType; import com.ruoyi.common.security.annotation.RequiresPermissions; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.user.domain.AccountUser; import com.ruoyi.user.service.IAccountUserService; /** * 会员用户 信息操作处理 * * 网关前缀 /account 由 StripPrefix=1 剥掉,故此处映射为 /user, * 外部实际路径是 /account/user/**。 * * @author ruoyi */ @RestController @RequestMapping("/user") public class AccountUserController extends BaseController { @Autowired private IAccountUserService accountUserService; /** * 查询会员列表 */ @RequiresPermissions("account:user:list") @GetMapping("/list") public TableDataInfo list(AccountUser accountUser) { startPage(); List list = accountUserService.selectAccountUserList(accountUser); return getDataTable(list); } /** * 导出会员列表 */ @RequiresPermissions("account:user:export") @Log(title = "会员管理", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, AccountUser accountUser) { List list = accountUserService.selectAccountUserList(accountUser); ExcelUtil util = new ExcelUtil(AccountUser.class); util.exportExcel(response, list, "会员数据"); } /** * 获取会员详细信息 */ @RequiresPermissions("account:user:query") @GetMapping(value = "/{userId}") public AjaxResult getInfo(@PathVariable Long userId) { return success(accountUserService.selectAccountUserById(userId)); } /** * 新增会员 */ @RequiresPermissions("account:user:add") @Log(title = "会员管理", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@Validated @RequestBody AccountUser accountUser) { if (!accountUserService.checkUsernameUnique(accountUser)) { return error("新增会员'" + accountUser.getUserName() + "'失败,用户名已存在"); } if (!accountUserService.checkPhoneUnique(accountUser)) { return error("新增会员'" + accountUser.getUserName() + "'失败,手机号已存在"); } if (StringUtils.isEmpty(accountUser.getPassword())) { return error("密码不能为空"); } accountUser.setCreateBy(SecurityUtils.getUsername()); return toAjax(accountUserService.insertAccountUser(accountUser)); } /** * 修改会员 */ @RequiresPermissions("account:user:edit") @Log(title = "会员管理", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@Validated @RequestBody AccountUser accountUser) { if (!accountUserService.checkUsernameUnique(accountUser)) { return error("修改会员'" + accountUser.getUserName() + "'失败,用户名已存在"); } if (!accountUserService.checkPhoneUnique(accountUser)) { return error("修改会员'" + accountUser.getUserName() + "'失败,手机号已存在"); } accountUser.setUpdateBy(SecurityUtils.getUsername()); return toAjax(accountUserService.updateAccountUser(accountUser)); } /** * 删除会员 */ @RequiresPermissions("account:user:remove") @Log(title = "会员管理", businessType = BusinessType.DELETE) @DeleteMapping("/{userIds}") public AjaxResult remove(@PathVariable Long[] userIds) { return toAjax(accountUserService.deleteAccountUserByIds(userIds)); } }