leutu
2024-05-08 7922905e4987789b636abdce1a240f4cee7c971b
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package com.terra.lfdcexp.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.terra.lfdcexp.config.R;
import com.terra.lfdcexp.entity.SysOrgEntity;
import com.terra.lfdcexp.entity.SysUserEntity;
import com.terra.lfdcexp.service.SysOrgService;
import com.terra.lfdcexp.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.Arrays;
import java.util.stream.Collectors;
 
 
/**
 * ${comments}
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2023-09-21 19:07:03
 */
@Api(tags = "SysUserController")
@RestController
@RequestMapping("generator/sysuser")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private SysOrgService sysOrgService ;
 
 
    @Autowired
    private WebSocket webSocket;
 
    @PostMapping("/websocket")
    public R sendWebSocketMsg(String msg) {
 
        webSocket.sendMessage(msg);
        return R.ok();
    }
 
    @PostMapping("/page")
    public R getPage(Page<SysUserEntity> page) {
        // 模拟复杂分页查询
        page.addOrder(OrderItem.asc("login_name"));
 
        return R.ok().put("page",   sysUserService.page(page));
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
 
    @ApiOperation(value = "generator:sysuser:list", notes = "")
    public R search( SysUserEntity sysUserEntity){
 
        if( sysUserEntity.getName() != null ){
 
            return R.ok().put("page", sysUserService.list(new QueryWrapper<SysUserEntity>().like("name",sysUserEntity.getName())));
        }
        if( sysUserEntity.getLoginName() != null ){
 
            return R.ok().put("page", sysUserService.list(new QueryWrapper<SysUserEntity>().like("login_name",sysUserEntity.getLoginName())));
        }
        if( sysUserEntity.getMobile() != null ){
 
            return R.ok().put("page", sysUserService.list(new QueryWrapper<SysUserEntity>().like("mobile",sysUserEntity.getMobile())));
        }
        if( sysUserEntity.getOrgId() != null ){
 
            return R.ok().put("page", sysUserService.list(new QueryWrapper<SysUserEntity>().eq("org_Id",sysUserEntity.getOrgId())));
        }
        return R.error(-3, "查询无结果");
    }
 
 
    @RequestMapping("/getUserByName")
 
    @ApiOperation(value = "getUserByName", notes = "")
    public R getUserByName( String name){
 
        if( name != null ){
            SysUserEntity sysUserEntity = sysUserService.getOne(new QueryWrapper<SysUserEntity>().eq("name",name));
            SysOrgEntity org = sysOrgService.getById(Integer.parseInt(sysUserEntity.getOrgId()));
            if( org == null ){
                return R.error(-2, "部门信息错误");
            }
            sysUserEntity.setOrgName( org.getName());
            return R.ok().put("sysUser", sysUserEntity);
        }
 
        return R.error(-1,"无数据");
    }
 
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
 
    @ApiOperation(value = "generator:sysuser:info", notes = "")
    public R info(@PathVariable("id") String id){
        SysUserEntity sysUser = sysUserService.getById(id);
 
        return R.ok().put("sysUser", sysUser);
    }
 
    /**
     * 保存
     */
    @RequestMapping("/save")
 
    @ApiOperation(value = "generator:sysuser:save", notes = "")
    public R save(@RequestBody SysUserEntity sysUser){
        sysUserService.save(sysUser);
 
        return R.ok();
    }
 
    /**
     * 修改
     */
    @RequestMapping("/update")
 
    @ApiOperation(value = "generator:sysuser:update", notes = "")
    public R update(@RequestBody SysUserEntity sysUser){
        sysUserService.updateById(sysUser);
 
        return R.ok();
    }
 
    /**
     * 删除
     */
    @RequestMapping("/delete")
 
    @ApiOperation(value = "generator:sysuser:delete", notes = "")
    public R delete(@RequestBody String[] ids){
        sysUserService.removeByIds(Arrays.asList(ids));
 
        return R.ok();
    }
 
}