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();
|
}
|
|
}
|