diff --git a/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationApplyEntity.java b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyEntity.java similarity index 61% rename from modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationApplyEntity.java rename to modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyEntity.java index bccc1b38e1..ab9699bb10 100644 --- a/modules/core/src/main/java/com/bytedesk/core/rbac/organization/OrganizationApplyEntity.java +++ b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyEntity.java @@ -1,8 +1,8 @@ /* * @Author: jackning 270580156@qq.com - * @Date: 2024-06-03 12:10:03 + * @Date: 2024-05-11 18:14:28 * @LastEditors: jackning 270580156@qq.com - * @LastEditTime: 2025-01-09 23:10:44 + * @LastEditTime: 2025-05-22 11:14:29 * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk * Please be aware of the BSL license restrictions before installing Bytedesk IM – * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. @@ -11,14 +11,12 @@ * 联系:270580156@qq.com * Copyright (c) 2024 by bytedesk.com, All Rights Reserved. */ -package com.bytedesk.core.rbac.organization; +package com.bytedesk.team.organization_apply; import com.bytedesk.core.base.BaseEntity; -import com.bytedesk.core.rbac.user.UserEntity; - +import com.bytedesk.core.constant.I18Consts; +import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import lombok.AllArgsConstructor; import lombok.Builder; @@ -26,26 +24,26 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; +import lombok.experimental.SuperBuilder; @Entity @Data -@Builder +@SuperBuilder @Accessors(chain = true) -@EqualsAndHashCode(callSuper = false, exclude = { "user" }) +@EqualsAndHashCode(callSuper = true) @AllArgsConstructor @NoArgsConstructor -@Table(name = "bytedesk_core_org_apply") +// @EntityListeners({OrganizationApplyEntityListener.class}) +@Table(name = "bytedesk_team_organization_apply") public class OrganizationApplyEntity extends BaseEntity { + private String name; - private String note; + @Builder.Default + private String description = I18Consts.I18N_DESCRIPTION; - // apply user - @ManyToOne(fetch = FetchType.LAZY) - private UserEntity user; - - // apply organization - @ManyToOne(fetch = FetchType.LAZY) - private OrganizationEntity organization; + @Builder.Default + @Column(name = "apply_type", nullable = false) + private String type = OrganizationApplyTypeEnum.CUSTOMER.name(); } diff --git a/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyEntityListener.java b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyEntityListener.java new file mode 100644 index 0000000000..88c2fcc3ec --- /dev/null +++ b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyEntityListener.java @@ -0,0 +1,51 @@ +/* + * @Author: jackning 270580156@qq.com + * @Date: 2025-02-25 09:52:34 + * @LastEditors: jackning 270580156@qq.com + * @LastEditTime: 2025-05-22 11:12:59 + * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk + * Please be aware of the BSL license restrictions before installing Bytedesk IM – + * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. + * Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE + * contact: 270580156@qq.com + * + * Copyright (c) 2025 by bytedesk.com, All Rights Reserved. + */ +package com.bytedesk.team.organization_apply; + +import org.springframework.stereotype.Component; +import org.springframework.util.SerializationUtils; + +import com.bytedesk.core.config.BytedeskEventPublisher; +import com.bytedesk.core.utils.ApplicationContextHolder; +import com.bytedesk.team.organization_apply.event.OrganizationApplyCreateEvent; +import com.bytedesk.team.organization_apply.event.OrganizationApplyUpdateEvent; + +import jakarta.persistence.PostPersist; +import jakarta.persistence.PostUpdate; + +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Component +public class OrganizationApplyEntityListener { + + @PostPersist + public void onPostPersist(OrganizationApplyEntity organizationApply) { + log.info("onPostPersist: {}", organizationApply); + OrganizationApplyEntity cloneOrganizationApply = SerializationUtils.clone(organizationApply); + // + BytedeskEventPublisher bytedeskEventPublisher = ApplicationContextHolder.getBean(BytedeskEventPublisher.class); + bytedeskEventPublisher.publishEvent(new OrganizationApplyCreateEvent(cloneOrganizationApply)); + } + + @PostUpdate + public void onPostUpdate(OrganizationApplyEntity organizationApply) { + log.info("onPostUpdate: {}", organizationApply); + OrganizationApplyEntity cloneOrganizationApply = SerializationUtils.clone(organizationApply); + // + BytedeskEventPublisher bytedeskEventPublisher = ApplicationContextHolder.getBean(BytedeskEventPublisher.class); + bytedeskEventPublisher.publishEvent(new OrganizationApplyUpdateEvent(cloneOrganizationApply)); + } + +} diff --git a/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyEventListener.java b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyEventListener.java new file mode 100644 index 0000000000..73bdcf403e --- /dev/null +++ b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyEventListener.java @@ -0,0 +1,27 @@ +/* + * @Author: jackning 270580156@qq.com + * @Date: 2025-02-25 09:44:18 + * @LastEditors: jackning 270580156@qq.com + * @LastEditTime: 2025-02-25 09:54:17 + * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk + * Please be aware of the BSL license restrictions before installing Bytedesk IM – + * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. + * Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE + * contact: 270580156@qq.com + * + * Copyright (c) 2025 by bytedesk.com, All Rights Reserved. + */ +package com.bytedesk.team.organization_apply; + +import org.springframework.stereotype.Component; + +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Component +@AllArgsConstructor +public class OrganizationApplyEventListener { + +} + diff --git a/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyExcel.java b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyExcel.java new file mode 100644 index 0000000000..4901c91446 --- /dev/null +++ b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyExcel.java @@ -0,0 +1,52 @@ +/* + * @Author: jackning 270580156@qq.com + * @Date: 2024-08-01 06:18:10 + * @LastEditors: jackning 270580156@qq.com + * @LastEditTime: 2025-05-21 12:56:29 + * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk + * Please be aware of the BSL license restrictions before installing Bytedesk IM – + * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. + * Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE + * contact: 270580156@qq.com + * 联系:270580156@qq.com + * Copyright (c) 2024 by bytedesk.com, All Rights Reserved. + */ +package com.bytedesk.team.organization_apply; + +import java.time.LocalDateTime; + +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.format.DateTimeFormat; +import com.alibaba.excel.annotation.write.style.ColumnWidth; + +import lombok.Data; + +/** + * https://github.com/alibaba/easyexcel + */ +@Data +public class OrganizationApplyExcel { + + @ExcelProperty(index = 0, value = "Name") + @ColumnWidth(20) + private String name; + + @ExcelProperty(index = 1, value = "Type") + @ColumnWidth(20) + private String type; + + @ExcelProperty(index = 2, value = "Color") + @ColumnWidth(20) + private String color; + + @DateTimeFormat("yyyy-MM-dd HH:mm:ss") + @ExcelProperty(value = "创建时间") + @ColumnWidth(20) + private LocalDateTime createdAt; + + @DateTimeFormat("yyyy-MM-dd HH:mm:ss") + @ExcelProperty(value = "修改时间") + @ColumnWidth(20) + private LocalDateTime updatedAt; + +} diff --git a/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyInitializer.java b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyInitializer.java new file mode 100644 index 0000000000..6ab4bee12a --- /dev/null +++ b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyInitializer.java @@ -0,0 +1,39 @@ +/* + * @Author: jackning 270580156@qq.com + * @Date: 2024-11-06 21:43:58 + * @LastEditors: jackning 270580156@qq.com + * @LastEditTime: 2025-03-20 13:28:11 + * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk + * Please be aware of the BSL license restrictions before installing Bytedesk IM – + * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. + * Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE + * contact: 270580156@qq.com + * 联系:270580156@qq.com + * Copyright (c) 2024 by bytedesk.com, All Rights Reserved. + */ +package com.bytedesk.team.organization_apply; + +import org.springframework.beans.factory.SmartInitializingSingleton; +import org.springframework.stereotype.Component; + +import lombok.AllArgsConstructor; + +@Component +@AllArgsConstructor +public class OrganizationApplyInitializer implements SmartInitializingSingleton { + + // private final AuthorityRestService authorityService; + + @Override + public void afterSingletonsInstantiated() { + initPermissions(); + } + + private void initPermissions() { + // for (PermissionEnum permission : PermissionEnum.values()) { + // String permissionValue = OrganizationApplyPermissions.ARTICLE_PREFIX + permission.name(); + // authorityService.createForPlatform(permissionValue); + // } + } + +} diff --git a/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyPermissions.java b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyPermissions.java new file mode 100644 index 0000000000..40ee3f21b9 --- /dev/null +++ b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyPermissions.java @@ -0,0 +1,20 @@ +/* + * @Author: jackning 270580156@qq.com + * @Date: 2024-11-05 16:58:18 + * @LastEditors: jackning 270580156@qq.com + * @LastEditTime: 2025-05-06 11:55:32 + * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk + * Please be aware of the BSL license restrictions before installing Bytedesk IM – + * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. + * Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE + * contact: 270580156@qq.com + * 联系:270580156@qq.com + * Copyright (c) 2024 by bytedesk.com, All Rights Reserved. + */ +package com.bytedesk.team.organization_apply; + +import com.bytedesk.core.base.BasePermissions; + +public class OrganizationApplyPermissions extends BasePermissions { + +} diff --git a/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyRepository.java b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyRepository.java new file mode 100644 index 0000000000..d463617bab --- /dev/null +++ b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyRepository.java @@ -0,0 +1,28 @@ +/* + * @Author: jackning 270580156@qq.com + * @Date: 2024-05-11 18:25:55 + * @LastEditors: jackning 270580156@qq.com + * @LastEditTime: 2025-03-11 09:23:20 + * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk + * Please be aware of the BSL license restrictions before installing Bytedesk IM – + * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. + * Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE + * contact: 270580156@qq.com + * 联系:270580156@qq.com + * Copyright (c) 2024 by bytedesk.com, All Rights Reserved. + */ +package com.bytedesk.team.organization_apply; + +import java.util.Optional; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +public interface OrganizationApplyRepository extends JpaRepository, JpaSpecificationExecutor { + + Optional findByUid(String uid); + + Boolean existsByUid(String uid); + + // Boolean existsByPlatform(String platform); +} diff --git a/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyRequest.java b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyRequest.java new file mode 100644 index 0000000000..fde30edcc5 --- /dev/null +++ b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyRequest.java @@ -0,0 +1,55 @@ +/* + * @Author: jackning 270580156@qq.com + * @Date: 2024-05-11 18:26:04 + * @LastEditors: jackning 270580156@qq.com + * @LastEditTime: 2025-03-20 12:51:55 + * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk + * Please be aware of the BSL license restrictions before installing Bytedesk IM – + * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. + * Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE + * contact: 270580156@qq.com + * 联系:270580156@qq.com + * Copyright (c) 2024 by bytedesk.com, All Rights Reserved. + */ +package com.bytedesk.team.organization_apply; + +import com.bytedesk.core.base.BaseRequest; +import com.bytedesk.core.constant.I18Consts; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; +import lombok.experimental.SuperBuilder; + +@Data +@SuperBuilder +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = false) +@AllArgsConstructor +@NoArgsConstructor +public class OrganizationApplyRequest extends BaseRequest { + + private String name; + + @Builder.Default + private String description = I18Consts.I18N_DESCRIPTION; + + // @Builder.Default + // private String type = OrganizationApplyTypeEnum.CUSTOMER.name(); + + @Builder.Default + private String color = "red"; + + @Builder.Default + private Integer order = 0; + + // @Builder.Default + // private String level = LevelEnum.ORGANIZATION.name(); + + // @Builder.Default + // private String platform = PlatformEnum.BYTEDESK.name(); + + // private String userUid; +} diff --git a/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyResponse.java b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyResponse.java new file mode 100644 index 0000000000..5009923989 --- /dev/null +++ b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyResponse.java @@ -0,0 +1,45 @@ +/* + * @Author: jackning 270580156@qq.com + * @Date: 2024-05-11 18:26:12 + * @LastEditors: jackning 270580156@qq.com + * @LastEditTime: 2025-05-08 12:40:30 + * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk + * Please be aware of the BSL license restrictions before installing Bytedesk IM – + * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. + * Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE + * contact: 270580156@qq.com + * 联系:270580156@qq.com + * Copyright (c) 2024 by bytedesk.com, All Rights Reserved. + */ +package com.bytedesk.team.organization_apply; + + +import com.bytedesk.core.base.BaseResponse; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; +import lombok.experimental.SuperBuilder; + +@Data +@SuperBuilder +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = true) +@AllArgsConstructor +@NoArgsConstructor +public class OrganizationApplyResponse extends BaseResponse { + + private String name; + + private String description; + + private String type; + + private String color; + + private Integer order; + + // private LocalDateTime createdAt; +} diff --git a/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyRestController.java b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyRestController.java new file mode 100644 index 0000000000..dc6ac6c641 --- /dev/null +++ b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyRestController.java @@ -0,0 +1,111 @@ +/* + * @Author: jackning 270580156@qq.com + * @Date: 2024-05-11 18:25:36 + * @LastEditors: jackning 270580156@qq.com + * @LastEditTime: 2025-05-22 11:21:46 + * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk + * Please be aware of the BSL license restrictions before installing Bytedesk IM – + * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. + * Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE + * contact: 270580156@qq.com + * 联系:270580156@qq.com + * Copyright (c) 2024 by bytedesk.com, All Rights Reserved. + */ +package com.bytedesk.team.organization_apply; + +import org.springframework.data.domain.Page; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.bytedesk.core.annotation.ActionAnnotation; +import com.bytedesk.core.base.BaseRestController; +import com.bytedesk.core.utils.JsonResult; + +import jakarta.servlet.http.HttpServletResponse; +import lombok.AllArgsConstructor; + +@RestController +@RequestMapping("/api/v1/org/apply") +@AllArgsConstructor +public class OrganizationApplyRestController extends BaseRestController { + + private final OrganizationApplyRestService organizationRestService; + + // @PreAuthorize(RolePermissions.ROLE_ADMIN) + @ActionAnnotation(title = "加入组织申请", action = "组织查询", description = "query organizationApply by org") + @Override + public ResponseEntity queryByOrg(OrganizationApplyRequest request) { + + Page organizationApplies = organizationRestService.queryByOrg(request); + + return ResponseEntity.ok(JsonResult.success(organizationApplies)); + } + + @ActionAnnotation(title = "加入组织申请", action = "用户查询", description = "query organizationApply by user") + @Override + public ResponseEntity queryByUser(OrganizationApplyRequest request) { + + Page organizationApplies = organizationRestService.queryByUser(request); + + return ResponseEntity.ok(JsonResult.success(organizationApplies)); + } + + @ActionAnnotation(title = "加入组织申请", action = "查询详情", description = "query organizationApply by uid") + @Override + public ResponseEntity queryByUid(OrganizationApplyRequest request) { + + OrganizationApplyResponse organizationApply = organizationRestService.queryByUid(request); + + return ResponseEntity.ok(JsonResult.success(organizationApply)); + } + + @ActionAnnotation(title = "加入组织申请", action = "新建", description = "create organizationApply") + @Override + // @PreAuthorize("hasAuthority('organizationApply_CREATE')") + public ResponseEntity create(OrganizationApplyRequest request) { + + OrganizationApplyResponse organizationApply = organizationRestService.create(request); + + return ResponseEntity.ok(JsonResult.success(organizationApply)); + } + + @ActionAnnotation(title = "加入组织申请", action = "更新", description = "update organizationApply") + @Override + // @PreAuthorize("hasAuthority('organizationApply_UPDATE')") + public ResponseEntity update(OrganizationApplyRequest request) { + + OrganizationApplyResponse organizationApply = organizationRestService.update(request); + + return ResponseEntity.ok(JsonResult.success(organizationApply)); + } + + @ActionAnnotation(title = "加入组织申请", action = "删除", description = "delete organizationApply") + @Override + // @PreAuthorize("hasAuthority('organizationApply_DELETE')") + public ResponseEntity delete(OrganizationApplyRequest request) { + + organizationRestService.delete(request); + + return ResponseEntity.ok(JsonResult.success()); + } + + @ActionAnnotation(title = "加入组织申请", action = "导出", description = "export organizationApply") + @Override + // @PreAuthorize("hasAuthority('organizationApply_EXPORT')") + @GetMapping("/export") + public Object export(OrganizationApplyRequest request, HttpServletResponse response) { + return exportTemplate( + request, + response, + organizationRestService, + OrganizationApplyExcel.class, + "加入组织申请", + "organizationApply" + ); + } + + + +} \ No newline at end of file diff --git a/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyRestService.java b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyRestService.java new file mode 100644 index 0000000000..bc22dddafa --- /dev/null +++ b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyRestService.java @@ -0,0 +1,181 @@ +/* + * @Author: jackning 270580156@qq.com + * @Date: 2024-05-11 18:25:45 + * @LastEditors: jackning 270580156@qq.com + * @LastEditTime: 2025-05-22 11:19:42 + * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk + * Please be aware of the BSL license restrictions before installing Bytedesk IM – + * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. + * Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE + * contact: 270580156@qq.com + * 联系:270580156@qq.com + * Copyright (c) 2024 by bytedesk.com, All Rights Reserved. + */ +package com.bytedesk.team.organization_apply; + +import java.util.Optional; + +import org.modelmapper.ModelMapper; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.orm.ObjectOptimisticLockingFailureException; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; +import com.bytedesk.core.base.BaseRestServiceWithExcel; +import com.bytedesk.core.rbac.auth.AuthService; +import com.bytedesk.core.rbac.user.UserEntity; +import com.bytedesk.core.uid.UidUtils; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +@Service +@AllArgsConstructor +public class OrganizationApplyRestService extends BaseRestServiceWithExcel { + + private final OrganizationApplyRepository organizationRepository; + + private final ModelMapper modelMapper; + + private final UidUtils uidUtils; + + private final AuthService authService; + + @Override + public Page queryByOrgEntity(OrganizationApplyRequest request) { + Pageable pageable = request.getPageable(); + Specification spec = OrganizationApplySpecification.search(request); + return organizationRepository.findAll(spec, pageable); + } + + @Override + public Page queryByOrg(OrganizationApplyRequest request) { + Page page = queryByOrgEntity(request); + return page.map(this::convertToResponse); + } + + @Override + public Page queryByUser(OrganizationApplyRequest request) { + UserEntity user = authService.getUser(); + if (user == null) { + throw new RuntimeException("user not found"); + } + request.setUserUid(user.getUid()); + // + return queryByOrg(request); + } + + @Override + public OrganizationApplyResponse queryByUid(OrganizationApplyRequest request) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Unimplemented method 'queryByUid'"); + } + + @Cacheable(value = "tag", key = "#uid", unless="#result==null") + @Override + public Optional findByUid(String uid) { + return organizationRepository.findByUid(uid); + } + + public Boolean existsByUid(String uid) { + return organizationRepository.existsByUid(uid); + } + + @Override + public OrganizationApplyResponse create(OrganizationApplyRequest request) { + // 判断是否已经存在 + if (StringUtils.hasText(request.getUid()) && existsByUid(request.getUid())) { + return convertToResponse(findByUid(request.getUid()).get()); + } + // + UserEntity user = authService.getUser(); + if (user != null) { + request.setUserUid(user.getUid()); + } + // + OrganizationApplyEntity entity = modelMapper.map(request, OrganizationApplyEntity.class); + if (!StringUtils.hasText(request.getUid())) { + entity.setUid(uidUtils.getUid()); + } + // + OrganizationApplyEntity savedEntity = save(entity); + if (savedEntity == null) { + throw new RuntimeException("Create tag failed"); + } + return convertToResponse(savedEntity); + } + + @Override + public OrganizationApplyResponse update(OrganizationApplyRequest request) { + Optional optional = organizationRepository.findByUid(request.getUid()); + if (optional.isPresent()) { + OrganizationApplyEntity entity = optional.get(); + modelMapper.map(request, entity); + // + OrganizationApplyEntity savedEntity = save(entity); + if (savedEntity == null) { + throw new RuntimeException("Update tag failed"); + } + return convertToResponse(savedEntity); + } + else { + throw new RuntimeException("OrganizationApply not found"); + } + } + + @Override + protected OrganizationApplyEntity doSave(OrganizationApplyEntity entity) { + return organizationRepository.save(entity); + } + + @Override + public OrganizationApplyEntity handleOptimisticLockingFailureException(ObjectOptimisticLockingFailureException e, OrganizationApplyEntity entity) { + try { + Optional latest = organizationRepository.findByUid(entity.getUid()); + if (latest.isPresent()) { + OrganizationApplyEntity latestEntity = latest.get(); + // 合并需要保留的数据 + latestEntity.setName(entity.getName()); + // latestEntity.setOrder(entity.getOrder()); + // latestEntity.setDeleted(entity.isDeleted()); + return organizationRepository.save(latestEntity); + } + } catch (Exception ex) { + log.error("无法处理乐观锁冲突: {}", ex.getMessage(), ex); + throw new RuntimeException("无法处理乐观锁冲突: " + ex.getMessage(), ex); + } + return null; + } + + @Override + public void deleteByUid(String uid) { + Optional optional = organizationRepository.findByUid(uid); + if (optional.isPresent()) { + optional.get().setDeleted(true); + save(optional.get()); + // tagRepository.delete(optional.get()); + } + else { + throw new RuntimeException("OrganizationApply not found"); + } + } + + @Override + public void delete(OrganizationApplyRequest request) { + deleteByUid(request.getUid()); + } + + @Override + public OrganizationApplyResponse convertToResponse(OrganizationApplyEntity entity) { + return modelMapper.map(entity, OrganizationApplyResponse.class); + } + + @Override + public OrganizationApplyExcel convertToExcel(OrganizationApplyEntity entity) { + return modelMapper.map(entity, OrganizationApplyExcel.class); + } + + +} diff --git a/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplySpecification.java b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplySpecification.java new file mode 100644 index 0000000000..3248b59c5e --- /dev/null +++ b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplySpecification.java @@ -0,0 +1,43 @@ +/* + * @Author: jackning 270580156@qq.com + * @Date: 2024-07-09 22:19:21 + * @LastEditors: jackning 270580156@qq.com + * @LastEditTime: 2025-03-03 14:25:07 + * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk + * Please be aware of the BSL license restrictions before installing Bytedesk IM – + * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. + * Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE + * contact: 270580156@qq.com + * 联系:270580156@qq.com + * Copyright (c) 2024 by bytedesk.com, All Rights Reserved. + */ +package com.bytedesk.team.organization_apply; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.data.jpa.domain.Specification; +import org.springframework.util.StringUtils; + +import com.bytedesk.core.base.BaseSpecification; + +import jakarta.persistence.criteria.Predicate; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class OrganizationApplySpecification extends BaseSpecification { + + public static Specification search(OrganizationApplyRequest request) { + log.info("request: {}", request); + return (root, query, criteriaBuilder) -> { + List predicates = new ArrayList<>(); + predicates.addAll(getBasicPredicates(root, criteriaBuilder, request.getOrgUid())); + // + if (StringUtils.hasText(request.getUserUid())) { + predicates.add(criteriaBuilder.equal(root.get("userUid"), request.getUserUid())); + } + // + return criteriaBuilder.and(predicates.toArray(new Predicate[0])); + }; + } +} diff --git a/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyTypeEnum.java b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyTypeEnum.java new file mode 100644 index 0000000000..a7fc15acfd --- /dev/null +++ b/modules/team/src/main/java/com/bytedesk/team/organization_apply/OrganizationApplyTypeEnum.java @@ -0,0 +1,20 @@ +/* + * @Author: jackning 270580156@qq.com + * @Date: 2024-07-23 17:02:46 + * @LastEditors: jackning 270580156@qq.com + * @LastEditTime: 2025-03-11 08:57:11 + * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk + * Please be aware of the BSL license restrictions before installing Bytedesk IM – + * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. + * Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE + * contact: 270580156@qq.com + * 联系:270580156@qq.com + * Copyright (c) 2024 by bytedesk.com, All Rights Reserved. + */ +package com.bytedesk.team.organization_apply; + +public enum OrganizationApplyTypeEnum { + THREAD, + CUSTOMER, + TICKET +} diff --git a/modules/team/src/main/java/com/bytedesk/team/organization_apply/event/OrganizationApplyCreateEvent.java b/modules/team/src/main/java/com/bytedesk/team/organization_apply/event/OrganizationApplyCreateEvent.java new file mode 100644 index 0000000000..609cbc5180 --- /dev/null +++ b/modules/team/src/main/java/com/bytedesk/team/organization_apply/event/OrganizationApplyCreateEvent.java @@ -0,0 +1,36 @@ +/* + * @Author: jackning 270580156@qq.com + * @Date: 2025-02-25 09:59:29 + * @LastEditors: jackning 270580156@qq.com + * @LastEditTime: 2025-05-22 11:21:01 + * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk + * Please be aware of the BSL license restrictions before installing Bytedesk IM – + * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. + * Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE + * contact: 270580156@qq.com + * + * Copyright (c) 2025 by bytedesk.com, All Rights Reserved. + */ +package com.bytedesk.team.organization_apply.event; + +import org.springframework.context.ApplicationEvent; + +import com.bytedesk.team.organization_apply.OrganizationApplyEntity; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@EqualsAndHashCode(callSuper = false) +public class OrganizationApplyCreateEvent extends ApplicationEvent { + + private static final long serialVersionUID = 1L; + + private OrganizationApplyEntity organizationApply; + + public OrganizationApplyCreateEvent(OrganizationApplyEntity organizationApply) { + super(organizationApply); + this.organizationApply = organizationApply; + } + +} diff --git a/modules/team/src/main/java/com/bytedesk/team/organization_apply/event/OrganizationApplyDeleteEvent.java b/modules/team/src/main/java/com/bytedesk/team/organization_apply/event/OrganizationApplyDeleteEvent.java new file mode 100644 index 0000000000..34b5c6ceff --- /dev/null +++ b/modules/team/src/main/java/com/bytedesk/team/organization_apply/event/OrganizationApplyDeleteEvent.java @@ -0,0 +1,35 @@ +/* + * @Author: jackning 270580156@qq.com + * @Date: 2025-02-25 12:31:16 + * @LastEditors: jackning 270580156@qq.com + * @LastEditTime: 2025-02-25 12:31:19 + * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk + * Please be aware of the BSL license restrictions before installing Bytedesk IM – + * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. + * Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE + * contact: 270580156@qq.com + * + * Copyright (c) 2025 by bytedesk.com, All Rights Reserved. + */ +package com.bytedesk.team.organization_apply.event; + +import org.springframework.context.ApplicationEvent; + +import com.bytedesk.team.organization_apply.OrganizationApplyEntity; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@EqualsAndHashCode(callSuper = false) +public class OrganizationApplyDeleteEvent extends ApplicationEvent { + + private static final long serialVersionUID = 1L; + + private OrganizationApplyEntity organizationApply; + + public OrganizationApplyDeleteEvent(OrganizationApplyEntity organizationApply) { + super(organizationApply); + this.organizationApply = organizationApply; + } +} diff --git a/modules/team/src/main/java/com/bytedesk/team/organization_apply/event/OrganizationApplyUpdateEvent.java b/modules/team/src/main/java/com/bytedesk/team/organization_apply/event/OrganizationApplyUpdateEvent.java new file mode 100644 index 0000000000..9465f6afd5 --- /dev/null +++ b/modules/team/src/main/java/com/bytedesk/team/organization_apply/event/OrganizationApplyUpdateEvent.java @@ -0,0 +1,36 @@ +/* + * @Author: jackning 270580156@qq.com + * @Date: 2025-02-25 09:59:29 + * @LastEditors: jackning 270580156@qq.com + * @LastEditTime: 2025-05-22 11:12:40 + * @Description: bytedesk.com https://github.com/Bytedesk/bytedesk + * Please be aware of the BSL license restrictions before installing Bytedesk IM – + * selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license. + * Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE + * contact: 270580156@qq.com + * + * Copyright (c) 2025 by bytedesk.com, All Rights Reserved. + */ +package com.bytedesk.team.organization_apply.event; + +import org.springframework.context.ApplicationEvent; + +import com.bytedesk.team.organization_apply.OrganizationApplyEntity; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@Data +@EqualsAndHashCode(callSuper = false) +public class OrganizationApplyUpdateEvent extends ApplicationEvent { + + private static final long serialVersionUID = 1L; + + private OrganizationApplyEntity organizationApply; + + public OrganizationApplyUpdateEvent(OrganizationApplyEntity organizationApply) { + super(organizationApply); + this.organizationApply = organizationApply; + } + +} diff --git a/modules/team/src/main/java/com/bytedesk/team/organization_apply/package-info.java b/modules/team/src/main/java/com/bytedesk/team/organization_apply/package-info.java new file mode 100644 index 0000000000..9fe8df1ccb --- /dev/null +++ b/modules/team/src/main/java/com/bytedesk/team/organization_apply/package-info.java @@ -0,0 +1,8 @@ +/** + * ByteDesk 标签管理包 + * 提供标签的CRUD、搜索等功能 + */ +@NonNullApi +package com.bytedesk.team.organization_apply; + +import org.springframework.lang.NonNullApi;