优化组织创建
This commit is contained in:
@@ -17,10 +17,11 @@ onMounted(() => {
|
|||||||
type: 'crud',
|
type: 'crud',
|
||||||
syncLocation: false,
|
syncLocation: false,
|
||||||
headerToolbar: [
|
headerToolbar: [
|
||||||
|
'reload',
|
||||||
{
|
{
|
||||||
type: 'action',
|
type: 'action',
|
||||||
label: '新增组织',
|
icon: 'fa fa-plus',
|
||||||
level: 'primary',
|
label: '',
|
||||||
actionType: 'dialog',
|
actionType: 'dialog',
|
||||||
dialog: {
|
dialog: {
|
||||||
title: '新增组织',
|
title: '新增组织',
|
||||||
@@ -30,10 +31,17 @@ onMounted(() => {
|
|||||||
method: 'post',
|
method: 'post',
|
||||||
url: `${information.baseUrl}/organization/save`,
|
url: `${information.baseUrl}/organization/save`,
|
||||||
data: {
|
data: {
|
||||||
name: '${name}',
|
code: '${code|default:undefined}',
|
||||||
|
name: '${name|default:undefined}',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
body: [
|
body: [
|
||||||
|
{
|
||||||
|
type: 'input-text',
|
||||||
|
name: 'code',
|
||||||
|
label: '组织编号',
|
||||||
|
placeholder: '不填则自动生成',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: 'input-text',
|
type: 'input-text',
|
||||||
name: 'name',
|
name: 'name',
|
||||||
@@ -65,14 +73,37 @@ onMounted(() => {
|
|||||||
hidden: true,
|
hidden: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
width: 150,
|
||||||
name: 'code',
|
name: 'code',
|
||||||
label: '组织编号',
|
label: '组织编号',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'name',
|
name: 'name',
|
||||||
label: '组织名称',
|
label: '组织名称',
|
||||||
required: true,
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
width: 100,
|
||||||
|
label: '操作',
|
||||||
|
type: 'operation',
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
type: 'action',
|
||||||
|
icon: 'fa fa-trash',
|
||||||
|
label: '删除',
|
||||||
|
level: 'danger',
|
||||||
|
size: 'xs',
|
||||||
|
actionType: 'ajax',
|
||||||
|
api: {
|
||||||
|
method: 'delete',
|
||||||
|
url: `${information.baseUrl}/jsonapi/organization/\${id}`,
|
||||||
|
},
|
||||||
|
messages: {
|
||||||
|
success: '删除成功',
|
||||||
|
failed: '删除失败',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import java.lang.annotation.Target;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.hibernate.annotations.IdGeneratorType;
|
import org.hibernate.annotations.IdGeneratorType;
|
||||||
import org.hibernate.annotations.ValueGenerationType;
|
|
||||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
import org.hibernate.id.IdentifierGenerator;
|
import org.hibernate.id.IdentifierGenerator;
|
||||||
|
|
||||||
@@ -39,6 +38,14 @@ public class SnowflakeId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long nextId() {
|
||||||
|
return Snowflake.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String nextStrId() {
|
||||||
|
return String.valueOf(Snowflake.next());
|
||||||
|
}
|
||||||
|
|
||||||
private static class Snowflake {
|
private static class Snowflake {
|
||||||
/**
|
/**
|
||||||
* 起始的时间戳
|
* 起始的时间戳
|
||||||
|
|||||||
@@ -48,4 +48,14 @@ public class Department {
|
|||||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "parent")
|
@OneToMany(fetch = FetchType.LAZY, mappedBy = "parent")
|
||||||
@ToString.Exclude
|
@ToString.Exclude
|
||||||
private Set<Department> children;
|
private Set<Department> children;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
public static class SaveVO {
|
||||||
|
private Long id;
|
||||||
|
private String name;
|
||||||
|
private Long organizationId;
|
||||||
|
private Long parentId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.lanyuanxiaoyao.server.entity;
|
|||||||
import com.lanyuanxiaoyao.server.configuration.Constants;
|
import com.lanyuanxiaoyao.server.configuration.Constants;
|
||||||
import com.lanyuanxiaoyao.server.configuration.database.SnowflakeId;
|
import com.lanyuanxiaoyao.server.configuration.database.SnowflakeId;
|
||||||
import com.yahoo.elide.annotation.Include;
|
import com.yahoo.elide.annotation.Include;
|
||||||
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.FetchType;
|
import jakarta.persistence.FetchType;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
@@ -32,7 +33,9 @@ public class Organization {
|
|||||||
@GeneratedValue(generator = "snowflakeId")
|
@GeneratedValue(generator = "snowflakeId")
|
||||||
@GenericGenerator(name = "snowflakeId", type = SnowflakeId.IdGenerator.class)
|
@GenericGenerator(name = "snowflakeId", type = SnowflakeId.IdGenerator.class)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
@Column(unique = true, nullable = false)
|
||||||
private String code;
|
private String code;
|
||||||
|
@Column(nullable = false)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "organization")
|
@OneToMany(fetch = FetchType.LAZY, mappedBy = "organization")
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.lanyuanxiaoyao.server.entity.mapper;
|
package com.lanyuanxiaoyao.server.entity.mapper;
|
||||||
|
|
||||||
import com.lanyuanxiaoyao.server.entity.Department;
|
import com.lanyuanxiaoyao.server.entity.Department;
|
||||||
import com.lanyuanxiaoyao.server.entity.vo.DepartmentSaveVO;
|
|
||||||
import com.lanyuanxiaoyao.server.service.DepartmentService;
|
import com.lanyuanxiaoyao.server.service.DepartmentService;
|
||||||
import com.lanyuanxiaoyao.server.service.OrganizationService;
|
import com.lanyuanxiaoyao.server.service.OrganizationService;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
@@ -19,9 +18,9 @@ import org.mapstruct.Mapping;
|
|||||||
DepartmentService.class,
|
DepartmentService.class,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
public interface DepartmentMapper extends EntityMapper<Department, DepartmentSaveVO> {
|
public interface DepartmentMapper extends EntityMapper<Department, Department.SaveVO> {
|
||||||
@Mapping(target = "organization", source = "organizationId")
|
@Mapping(target = "organization", source = "organizationId")
|
||||||
@Mapping(target = "parent", source = "parentId")
|
@Mapping(target = "parent", source = "parentId")
|
||||||
@Override
|
@Override
|
||||||
Department fromVO(DepartmentSaveVO saveVO);
|
Department fromVO(Department.SaveVO saveVO);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.lanyuanxiaoyao.server.entity.mapper;
|
package com.lanyuanxiaoyao.server.entity.mapper;
|
||||||
|
|
||||||
|
import com.lanyuanxiaoyao.server.configuration.database.SnowflakeId;
|
||||||
import com.lanyuanxiaoyao.server.entity.Organization;
|
import com.lanyuanxiaoyao.server.entity.Organization;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.Mapping;
|
import org.mapstruct.Mapping;
|
||||||
@@ -10,9 +11,13 @@ import org.mapstruct.Mapping;
|
|||||||
* @author lanyuanxiaoyao
|
* @author lanyuanxiaoyao
|
||||||
* @version 20250327
|
* @version 20250327
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper(
|
||||||
|
imports = {
|
||||||
|
SnowflakeId.class
|
||||||
|
}
|
||||||
|
)
|
||||||
public interface OrganizationMapper extends EntityMapper<Organization, Organization.SaveVO> {
|
public interface OrganizationMapper extends EntityMapper<Organization, Organization.SaveVO> {
|
||||||
@Mapping(target = "code", defaultExpression = "java(String.valueOf(creationVO.getId()))")
|
@Mapping(target = "code", defaultExpression = "java(SnowflakeId.nextStrId())")
|
||||||
@Override
|
@Override
|
||||||
Organization fromVO(Organization.SaveVO creationVO);
|
Organization fromVO(Organization.SaveVO creationVO);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.lanyuanxiaoyao.server.entity.vo;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import lombok.ToString;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@ToString
|
|
||||||
public class DepartmentSaveVO {
|
|
||||||
private Long id;
|
|
||||||
private String name;
|
|
||||||
private Long organizationId;
|
|
||||||
private Long parentId;
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.lanyuanxiaoyao.server.service.base;
|
package com.lanyuanxiaoyao.server.service.base;
|
||||||
|
|
||||||
import com.blinkfox.fenix.jpa.FenixJpaRepository;
|
import com.blinkfox.fenix.jpa.FenixJpaRepository;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
public abstract class AbstractService<ENTITY, ID> {
|
public abstract class AbstractService<ENTITY, ID> {
|
||||||
public abstract FenixJpaRepository<ENTITY, ID> getRepository();
|
public abstract FenixJpaRepository<ENTITY, ID> getRepository();
|
||||||
@@ -11,6 +12,7 @@ public abstract class AbstractService<ENTITY, ID> {
|
|||||||
return getRepository().getReferenceById(id);
|
return getRepository().getReferenceById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public ID save(ENTITY entity) {
|
public ID save(ENTITY entity) {
|
||||||
ENTITY saved = getRepository().saveOrUpdateByNotNullProperties(entity);
|
ENTITY saved = getRepository().saveOrUpdateByNotNullProperties(entity);
|
||||||
return getId(saved);
|
return getId(saved);
|
||||||
|
|||||||
Reference in New Issue
Block a user