从简单到复杂完善组织架构

This commit is contained in:
2025-04-18 18:24:08 +08:00
parent e615aefaee
commit c73a7b48fa
14 changed files with 78 additions and 238 deletions

View File

@@ -1,13 +0,0 @@
package com.lanyuanxiaoyao.server.configuration.amis;
/**
* Crud 响应
*
* @author lanyuanxiaoyao
* @date 2023-07-06
*/
public class AmisItemResponse extends AmisMapResponse {
public void setDetail(Object detail) {
getData().put("item", detail);
}
}

View File

@@ -1,30 +0,0 @@
package com.lanyuanxiaoyao.server.configuration.amis;
/**
* Crud 响应
*
* @author lanyuanxiaoyao
* @date 2023-07-06
*/
public class AmisListResponse extends AmisMapResponse {
public void setData(Iterable<?> list) {
getData().put("items", list);
}
public void setTotal(Long total) {
getData().put("total", total);
}
public void setTotal(Integer total) {
setTotal(total.longValue());
}
public void setData(Iterable<?> list, Long total) {
setData(list);
setTotal(total);
}
public void setData(Iterable<?> list, Integer total) {
setData(list, total.longValue());
}
}

View File

@@ -1,21 +0,0 @@
package com.lanyuanxiaoyao.server.configuration.amis;
import java.util.HashMap;
import java.util.Map;
/**
* Map 响应
*
* @author lanyuanxiaoyao
* @date 2023-07-06
*/
public class AmisMapResponse extends AmisResponse<Map<String, Object>> {
public AmisMapResponse() {
setData(new HashMap<>());
}
public AmisMapResponse setData(String key, Object value) {
getData().put(key, value);
return this;
}
}

View File

@@ -1,106 +0,0 @@
package com.lanyuanxiaoyao.server.configuration.amis;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* Amis 组件结构化返回值
*
* @author lanyuanxiaoyao
* @date 2022-09-21
*/
@ToString
@Getter
@Setter
public class AmisResponse<T> {
private static final int SUCCESS_STATUS = 0;
private static final int ERROR_STATUS = 500;
private static final String SUCCESS_MESSAGE = "成功";
private static final String ERROR_MESSAGE = "错误";
private Integer status;
@JsonProperty("msg")
private String message;
private T data;
public static AmisResponse<Object> responseError() {
return responseError(ERROR_MESSAGE);
}
public static AmisResponse<Object> responseError(String message) {
AmisResponse<Object> response = new AmisResponse<>();
response.setStatus(ERROR_STATUS);
response.setMessage(message);
return response;
}
public static AmisResponse<Object> responseSuccess() {
return responseSuccess(SUCCESS_MESSAGE);
}
public static AmisResponse<Object> responseSuccess(String message) {
AmisResponse<Object> response = new AmisResponse<>();
response.setStatus(SUCCESS_STATUS);
response.setMessage(message);
return response;
}
public static <E> AmisResponse<E> responseSuccess(String message, E data) {
AmisResponse<E> response = new AmisResponse<>();
response.setStatus(SUCCESS_STATUS);
response.setMessage(message);
response.setData(data);
return response;
}
public static <E> AmisResponse<E> responseSuccess(E data) {
return responseSuccess(SUCCESS_MESSAGE, data);
}
public static AmisMapResponse responseMapData() {
AmisMapResponse response = new AmisMapResponse();
response.setStatus(SUCCESS_STATUS);
response.setMessage(SUCCESS_MESSAGE);
return response;
}
public static AmisMapResponse responseMapData(Map<String, Object> data) {
AmisMapResponse response = responseMapData();
response.setData(data);
return response;
}
public static AmisMapResponse responseMapData(String key, Object value) {
AmisMapResponse response = responseMapData();
response.setData(key, value);
return response;
}
public static AmisListResponse responseListData(Iterable<?> data) {
AmisListResponse response = new AmisListResponse();
response.setStatus(SUCCESS_STATUS);
response.setMessage(SUCCESS_MESSAGE);
response.setData(data);
return response;
}
public static AmisListResponse responseListData(Iterable<?> data, Integer total) {
AmisListResponse response = responseListData(data);
response.setTotal(total);
return response;
}
public static AmisListResponse responseListData(Iterable<?> data, Long total) {
AmisListResponse response = responseListData(data);
response.setTotal(total);
return response;
}
public static AmisItemResponse responseItemData(Object detail) {
AmisItemResponse response = new AmisItemResponse();
response.setDetail(detail);
return response;
}
}

View File

@@ -1,6 +1,5 @@
package com.lanyuanxiaoyao.server.controller.base;
import com.lanyuanxiaoyao.server.configuration.amis.AmisResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
@@ -20,8 +19,8 @@ public class ErrorController {
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
@ExceptionHandler(Throwable.class)
public AmisResponse<Object> errorHandler(Throwable throwable) {
public String errorHandler(Throwable throwable) {
logger.error("Error", throwable);
return AmisResponse.responseError(throwable.getMessage());
return throwable.getMessage();
}
}

View File

@@ -35,17 +35,13 @@ public class Department {
@Id
@GeneratedValue(generator = "snowflakeId")
@GenericGenerator(name = "snowflakeId", type = SnowflakeId.IdGenerator.class)
private Long departmentId;
private String departmentName;
private Long id;
private String name;
@ManyToOne(optional = false)
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Organization organization;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "department")
@ToString.Exclude
private Set<User> users;
@ManyToOne
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Department parent;

View File

@@ -31,12 +31,8 @@ public class Organization {
@Id
@GeneratedValue(generator = "snowflakeId")
@GenericGenerator(name = "snowflakeId", type = SnowflakeId.IdGenerator.class)
private Long organizationId;
private String organizationName;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "organization")
@ToString.Exclude
private Set<User> users;
private Long id;
private String name;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "organization")
@ToString.Exclude

View File

@@ -1,47 +0,0 @@
package com.lanyuanxiaoyao.server.entity;
import com.lanyuanxiaoyao.server.configuration.Constants;
import com.lanyuanxiaoyao.server.configuration.database.SnowflakeId;
import com.yahoo.elide.annotation.Include;
import jakarta.persistence.ConstraintMode;
import jakarta.persistence.Entity;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.GenericGenerator;
/**
* 用户
*
* @author lanyuanxiaoyao
* @version 20250327
*/
@Getter
@Setter
@ToString
@Entity
@Table(name = Constants.DATABASE_TABLE_PREFIX + "user")
@Include
public class User {
@Id
@GeneratedValue(generator = "snowflakeId")
@GenericGenerator(name = "snowflakeId", type = SnowflakeId.IdGenerator.class)
private Long userId;
private String userCode;
private String userNickname;
private String userSecret;
@ManyToOne
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Organization organization;
@ManyToOne
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
private Department department;
}