package com.gear.admin.controller.swx; import java.util.List; import javax.servlet.http.HttpServletResponse; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gear.common.builder.WhereBuilder; import com.gear.common.utils.sign.Md5Utils; import com.gear.common.vo.Result; import com.gear.swx.domain.SwxRechargeRecord; import org.apache.logging.log4j.util.Strings; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.gear.common.annotation.Log; import com.gear.common.core.controller.BaseController; import com.gear.common.enums.BusinessType; import com.gear.swx.domain.SwxUser; import com.gear.swx.service.ISwxUserService; import com.gear.common.utils.poi.ExcelUtil; /** * 用户管理Controller * * @author czx * @date 2023-11-18 */ @RestController @RequestMapping("/swx/user") public class SwxUserController extends BaseController { @Autowired private ISwxUserService swxUserService; /** * 查询用户管理列表 */ @PreAuthorize("@ss.hasPermi('swx:user:list')") @GetMapping("/list") public Result> list(SwxUser swxUser, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize){ QueryWrapper queryWrapper = WhereBuilder.build(swxUser); queryWrapper.lambda().orderByDesc(SwxUser::getCreateTime); Page page = new Page(pageNo, pageSize); IPage pageList = swxUserService.page(page, queryWrapper); return Result.OK(pageList); } /** * 导出用户管理列表 */ @PreAuthorize("@ss.hasPermi('swx:user:export')") @Log(title = "用户管理", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, SwxUser swxUser){ QueryWrapper queryWrapper = WhereBuilder.build(swxUser); List list = swxUserService.list(queryWrapper); ExcelUtil util = new ExcelUtil(SwxUser.class); util.exportExcel(response, list, "用户管理数据"); } /** * 获取用户管理详细信息 */ @PreAuthorize("@ss.hasPermi('swx:user:query')") @GetMapping(value = "/{id}") public Result getInfo(@PathVariable("id") String id){ SwxUser swxUser = swxUserService.getById(id); if(swxUser==null) { return Result.error("未找到对应数据"); } return Result.OK(swxUser); } /** * 新增用户管理 */ @PreAuthorize("@ss.hasPermi('swx:user:add')") @Log(title = "用户管理", businessType = BusinessType.INSERT) @PostMapping public Result add(@RequestBody SwxUser swxUser){ swxUserService.save(swxUser); return Result.ok("添加成功!"); } /** * 修改用户管理 */ @PreAuthorize("@ss.hasPermi('swx:user:edit')") @Log(title = "用户管理", businessType = BusinessType.UPDATE) @PutMapping public Result edit(@RequestBody SwxUser swxUser){ if (!Strings.isEmpty(swxUser.getPassword())){ String md5Pass = Md5Utils.hash(swxUser.getPassword()); swxUser.setPassword(md5Pass); } swxUserService.updateById(swxUser); return Result.ok("编辑成功!"); } }