部门人员代码结构
This commit is contained in:
@@ -0,0 +1,78 @@
|
|||||||
|
package com.rj.controller;
|
||||||
|
|
||||||
|
import com.rj.entity.LbDepartmentUser;
|
||||||
|
import com.rj.service.ILbDepartmentUserService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/lbDepartmentUser")
|
||||||
|
@Tag(name = "部门用户", description = "lb_department_user增删改查与分页")
|
||||||
|
public class LbDepartmentUserController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ILbDepartmentUserService lbDepartmentUserService;
|
||||||
|
|
||||||
|
@PostMapping("/add")
|
||||||
|
@Operation(summary = "新增")
|
||||||
|
public ResponseEntity<Map<String, Object>> add(
|
||||||
|
@Parameter(description = "实体", required = true) @RequestBody LbDepartmentUser entity) {
|
||||||
|
Map<String, Object> result = lbDepartmentUserService.add(entity);
|
||||||
|
Boolean success = (Boolean) result.get("success");
|
||||||
|
if (success != null && success) {
|
||||||
|
return ResponseEntity.ok(result);
|
||||||
|
}
|
||||||
|
return ResponseEntity.badRequest().body(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update")
|
||||||
|
@Operation(summary = "编辑")
|
||||||
|
public ResponseEntity<Map<String, Object>> update(
|
||||||
|
@Parameter(description = "实体", required = true) @RequestBody LbDepartmentUser entity) {
|
||||||
|
Map<String, Object> result = lbDepartmentUserService.update(entity);
|
||||||
|
Boolean success = (Boolean) result.get("success");
|
||||||
|
if (success != null && success) {
|
||||||
|
return ResponseEntity.ok(result);
|
||||||
|
}
|
||||||
|
return ResponseEntity.badRequest().body(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete/{id}")
|
||||||
|
@Operation(summary = "删除")
|
||||||
|
public ResponseEntity<Map<String, Object>> delete(
|
||||||
|
@Parameter(description = "主键ID(UUID)", required = true) @PathVariable String id) {
|
||||||
|
Map<String, Object> result = lbDepartmentUserService.deleteById(id);
|
||||||
|
Boolean success = (Boolean) result.get("success");
|
||||||
|
if (success != null && success) {
|
||||||
|
return ResponseEntity.ok(result);
|
||||||
|
}
|
||||||
|
return ResponseEntity.badRequest().body(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
@Operation(summary = "分页查询")
|
||||||
|
public ResponseEntity<Map<String, Object>> list(
|
||||||
|
@RequestParam(defaultValue = "1") Integer current,
|
||||||
|
@RequestParam(defaultValue = "10") Integer size,
|
||||||
|
@RequestParam(required = false) String tenantId,
|
||||||
|
@RequestParam(required = false) String userId,
|
||||||
|
@RequestParam(required = false) String parentId,
|
||||||
|
@RequestParam(required = false) String name,
|
||||||
|
@RequestParam(required = false) String phone,
|
||||||
|
@RequestParam(required = false) String industry) {
|
||||||
|
Map<String, Object> result = lbDepartmentUserService.pageQuery(
|
||||||
|
current, size, tenantId, userId, parentId, name, phone, industry
|
||||||
|
);
|
||||||
|
Boolean success = (Boolean) result.get("success");
|
||||||
|
if (success != null && success) {
|
||||||
|
return ResponseEntity.ok(result);
|
||||||
|
}
|
||||||
|
return ResponseEntity.internalServerError().body(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
65
src/main/java/com/rj/entity/LbDepartmentUser.java
Normal file
65
src/main/java/com/rj/entity/LbDepartmentUser.java
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
package com.rj.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@TableName("lb_department_user")
|
||||||
|
@Schema(description = "部门用户表")
|
||||||
|
public class LbDepartmentUser implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@TableId("id")
|
||||||
|
@Schema(description = "表id(UUID)")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@TableField("user_id")
|
||||||
|
@Schema(description = "用户ID")
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
@TableField("parent_id")
|
||||||
|
@Schema(description = "父id(UUID)")
|
||||||
|
private String parentId;
|
||||||
|
|
||||||
|
@TableField("tenant_id")
|
||||||
|
@Schema(description = "租户id")
|
||||||
|
private String tenantId;
|
||||||
|
|
||||||
|
@TableField("name")
|
||||||
|
@Schema(description = "姓名")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@TableField("phone")
|
||||||
|
@Schema(description = "电话")
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
@TableField("address")
|
||||||
|
@Schema(description = "地址")
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
@TableField("industry")
|
||||||
|
@Schema(description = "从事的行业")
|
||||||
|
private String industry;
|
||||||
|
|
||||||
|
@TableField("join_date")
|
||||||
|
@Schema(description = "加入日期(不含时分秒)")
|
||||||
|
private LocalDate joinDate;
|
||||||
|
|
||||||
|
@TableField("create_time")
|
||||||
|
@Schema(description = "创建时间")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@TableField("update_time")
|
||||||
|
@Schema(description = "修改时间")
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
}
|
||||||
9
src/main/java/com/rj/mapper/LbDepartmentUserMapper.java
Normal file
9
src/main/java/com/rj/mapper/LbDepartmentUserMapper.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package com.rj.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.rj.entity.LbDepartmentUser;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface LbDepartmentUserMapper extends BaseMapper<LbDepartmentUser> {
|
||||||
|
}
|
||||||
24
src/main/java/com/rj/service/ILbDepartmentUserService.java
Normal file
24
src/main/java/com/rj/service/ILbDepartmentUserService.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package com.rj.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.rj.entity.LbDepartmentUser;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface ILbDepartmentUserService extends IService<LbDepartmentUser> {
|
||||||
|
|
||||||
|
Map<String, Object> add(LbDepartmentUser entity);
|
||||||
|
|
||||||
|
Map<String, Object> update(LbDepartmentUser entity);
|
||||||
|
|
||||||
|
Map<String, Object> deleteById(String id);
|
||||||
|
|
||||||
|
Map<String, Object> pageQuery(Integer current,
|
||||||
|
Integer size,
|
||||||
|
String tenantId,
|
||||||
|
String userId,
|
||||||
|
String parentId,
|
||||||
|
String name,
|
||||||
|
String phone,
|
||||||
|
String industry);
|
||||||
|
}
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
package com.rj.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.rj.entity.LbDepartmentUser;
|
||||||
|
import com.rj.mapper.LbDepartmentUserMapper;
|
||||||
|
import com.rj.service.ILbDepartmentUserService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class LbDepartmentUserServiceImpl extends ServiceImpl<LbDepartmentUserMapper, LbDepartmentUser>
|
||||||
|
implements ILbDepartmentUserService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> add(LbDepartmentUser entity) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
try {
|
||||||
|
if (entity.getUserId() == null || entity.getUserId().trim().isEmpty()) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "userId不能为空");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (entity.getTenantId() == null || entity.getTenantId().trim().isEmpty()) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "tenantId不能为空");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (entity.getName() == null || entity.getName().trim().isEmpty()) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "name不能为空");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entity.getId() == null || entity.getId().trim().isEmpty()) {
|
||||||
|
entity.setId(UUID.randomUUID().toString());
|
||||||
|
}
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
entity.setCreateTime(now);
|
||||||
|
entity.setUpdateTime(now);
|
||||||
|
|
||||||
|
boolean ok = this.save(entity);
|
||||||
|
result.put("success", ok);
|
||||||
|
result.put("message", ok ? "新增成功" : "新增失败");
|
||||||
|
if (ok) {
|
||||||
|
result.put("data", entity);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} catch (Exception e) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "新增异常:" + e.getMessage());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> update(LbDepartmentUser entity) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
try {
|
||||||
|
if (entity.getId() == null || entity.getId().trim().isEmpty()) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "id不能为空");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
entity.setUpdateTime(LocalDateTime.now());
|
||||||
|
boolean ok = this.updateById(entity);
|
||||||
|
result.put("success", ok);
|
||||||
|
result.put("message", ok ? "编辑成功" : "编辑失败");
|
||||||
|
if (ok) {
|
||||||
|
result.put("data", this.getById(entity.getId()));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} catch (Exception e) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "编辑异常:" + e.getMessage());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> deleteById(String id) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
try {
|
||||||
|
boolean ok = this.removeById(id);
|
||||||
|
result.put("success", ok);
|
||||||
|
result.put("message", ok ? "删除成功" : "删除失败");
|
||||||
|
return result;
|
||||||
|
} catch (Exception e) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "删除异常:" + e.getMessage());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> pageQuery(Integer current,
|
||||||
|
Integer size,
|
||||||
|
String tenantId,
|
||||||
|
String userId,
|
||||||
|
String parentId,
|
||||||
|
String name,
|
||||||
|
String phone,
|
||||||
|
String industry) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
try {
|
||||||
|
if (current == null || current < 1) {
|
||||||
|
current = 1;
|
||||||
|
}
|
||||||
|
if (size == null || size < 1) {
|
||||||
|
size = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
LambdaQueryWrapper<LbDepartmentUser> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
if (tenantId != null && !tenantId.trim().isEmpty()) {
|
||||||
|
queryWrapper.eq(LbDepartmentUser::getTenantId, tenantId.trim());
|
||||||
|
}
|
||||||
|
if (userId != null && !userId.trim().isEmpty()) {
|
||||||
|
queryWrapper.eq(LbDepartmentUser::getUserId, userId.trim());
|
||||||
|
}
|
||||||
|
if (parentId != null && !parentId.trim().isEmpty()) {
|
||||||
|
queryWrapper.eq(LbDepartmentUser::getParentId, parentId.trim());
|
||||||
|
}
|
||||||
|
if (name != null && !name.trim().isEmpty()) {
|
||||||
|
queryWrapper.like(LbDepartmentUser::getName, name.trim());
|
||||||
|
}
|
||||||
|
if (phone != null && !phone.trim().isEmpty()) {
|
||||||
|
queryWrapper.like(LbDepartmentUser::getPhone, phone.trim());
|
||||||
|
}
|
||||||
|
if (industry != null && !industry.trim().isEmpty()) {
|
||||||
|
queryWrapper.like(LbDepartmentUser::getIndustry, industry.trim());
|
||||||
|
}
|
||||||
|
queryWrapper.orderByDesc(LbDepartmentUser::getUpdateTime)
|
||||||
|
.orderByDesc(LbDepartmentUser::getCreateTime);
|
||||||
|
|
||||||
|
Page<LbDepartmentUser> page = this.page(new Page<>(current, size), queryWrapper);
|
||||||
|
result.put("success", true);
|
||||||
|
result.put("message", "查询成功");
|
||||||
|
result.put("data", page.getRecords());
|
||||||
|
result.put("total", page.getTotal());
|
||||||
|
result.put("current", page.getCurrent());
|
||||||
|
result.put("size", page.getSize());
|
||||||
|
result.put("pages", page.getPages());
|
||||||
|
return result;
|
||||||
|
} catch (Exception e) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "查询异常:" + e.getMessage());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user