zj
2025-01-06 0e7b38c2b3af72ea2a7f8a2fcbaad4d78e2c1977
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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<IPage<SwxUser>> list(SwxUser swxUser,
        @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
        @RequestParam(name="pageSize", defaultValue="10") Integer pageSize){
        QueryWrapper<SwxUser> queryWrapper = WhereBuilder.build(swxUser);
        queryWrapper.lambda().orderByDesc(SwxUser::getCreateTime);
        Page<SwxUser> page = new Page<SwxUser>(pageNo, pageSize);
        IPage<SwxUser> 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<SwxUser> queryWrapper = WhereBuilder.build(swxUser);
        List<SwxUser> list = swxUserService.list(queryWrapper);
        ExcelUtil<SwxUser> util = new ExcelUtil<SwxUser>(SwxUser.class);
        util.exportExcel(response, list, "用户管理数据");
    }
 
    /**
     * 获取用户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('swx:user:query')")
    @GetMapping(value = "/{id}")
    public Result<SwxUser>  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<String> add(@RequestBody SwxUser swxUser){
        swxUserService.save(swxUser);
        return Result.ok("添加成功!");
    }
 
    /**
     * 修改用户管理
     */
    @PreAuthorize("@ss.hasPermi('swx:user:edit')")
    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public  Result<String> edit(@RequestBody SwxUser swxUser){
        if (!Strings.isEmpty(swxUser.getPassword())){
            String md5Pass = Md5Utils.hash(swxUser.getPassword());
            swxUser.setPassword(md5Pass);
        }
        swxUserService.updateById(swxUser);
        return Result.ok("编辑成功!");
    }
 
}