feat:权限功能
This commit is contained in:
parent
93c1d3f346
commit
0d054de1e8
1
pom.xml
1
pom.xml
|
@ -14,7 +14,6 @@
|
||||||
<name>Route</name>
|
<name>Route</name>
|
||||||
<description>Route</description>
|
<description>Route</description>
|
||||||
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.chint.application.commands;
|
||||||
|
|
||||||
|
import com.chint.domain.aggregates.user.User;
|
||||||
|
import com.chint.infrastructure.echo_framework.command.Command;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UserRoleCommand extends Command {
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
public UserRoleCommand user(User user) {
|
||||||
|
this.user = user;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,10 @@
|
||||||
package com.chint.application.dtos.response;
|
package com.chint.application.dtos.response;
|
||||||
|
|
||||||
|
import com.chint.domain.value_object.system.SystemOrganizationVO;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.annotation.Transient;
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class UserRes {
|
public class UserRes {
|
||||||
|
@ -15,10 +17,8 @@ public class UserRes {
|
||||||
private String gender;
|
private String gender;
|
||||||
private String phoneNumber;
|
private String phoneNumber;
|
||||||
private String password;
|
private String password;
|
||||||
@Transient
|
|
||||||
private String rankCode;
|
private String rankCode;
|
||||||
@Transient
|
|
||||||
private String companyCode;
|
private String companyCode;
|
||||||
@Transient
|
|
||||||
private String workStatus;
|
private String workStatus;
|
||||||
|
private List<SystemOrganizationVO> roleOrgList;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.chint.application.dtos.system;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class RoleOrgParam {
|
||||||
|
private Long roleId;
|
||||||
|
private String roleName;
|
||||||
|
private String roleDesc;
|
||||||
|
private Long userId;
|
||||||
|
private List<Long> orgIdList;
|
||||||
|
private List<Long> roleIdList;
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package com.chint.application.dtos.system;
|
||||||
|
|
||||||
|
public class RoleParam {
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package com.chint.application.dtos;
|
package com.chint.application.dtos.system;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package com.chint.application.dtos;
|
package com.chint.application.dtos.system;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
|
||||||
import com.chint.domain.aggregates.system.SystemAnnouncement;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
|
@ -0,0 +1,8 @@
|
||||||
|
package com.chint.application.dtos.system;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SystemOrganizationParam {
|
||||||
|
private Long id;
|
||||||
|
}
|
|
@ -133,6 +133,4 @@ public class OrderOutController {
|
||||||
public Result<PageResult<RouteOrderFiledVO>> queryRoutOrderField(@RequestBody RoutOrderFieldParam param) {
|
public Result<PageResult<RouteOrderFiledVO>> queryRoutOrderField(@RequestBody RoutOrderFieldParam param) {
|
||||||
return Result.Success(SUCCESS, orderQuery.queryRouteOrderFiled(param));
|
return Result.Success(SUCCESS, orderQuery.queryRouteOrderFiled(param));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
package com.chint.application.system;
|
package com.chint.application.system;
|
||||||
|
|
||||||
import com.chint.application.dtos.OrganizationTicketClerk;
|
import com.chint.application.dtos.OrganizationTicketClerk;
|
||||||
import com.chint.application.dtos.SystemAnnouncementDTO;
|
import com.chint.application.dtos.system.SystemAnnouncementDTO;
|
||||||
import com.chint.application.dtos.SystemAnnouncementVO;
|
import com.chint.application.dtos.system.SystemAnnouncementVO;
|
||||||
|
import com.chint.application.dtos.system.SystemOrganizationParam;
|
||||||
import com.chint.domain.aggregates.system.SystemAnnouncement;
|
import com.chint.domain.aggregates.system.SystemAnnouncement;
|
||||||
|
import com.chint.domain.aggregates.system.SystemOrganization;
|
||||||
import com.chint.domain.exceptions.NotFoundException;
|
import com.chint.domain.exceptions.NotFoundException;
|
||||||
import com.chint.domain.repository.SystemAnnouncementRepository;
|
import com.chint.domain.repository.SystemAnnouncementRepository;
|
||||||
|
import com.chint.domain.repository.SystemOrganizationRepository;
|
||||||
import com.chint.domain.service.SystemDomainService;
|
import com.chint.domain.service.SystemDomainService;
|
||||||
|
import com.chint.domain.value_object.system.SystemOrganizationVO;
|
||||||
import com.chint.infrastructure.util.Result;
|
import com.chint.infrastructure.util.Result;
|
||||||
import com.chint.interfaces.rest.data_center.org.OrgRequest;
|
import com.chint.interfaces.rest.data_center.org.OrgRequest;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
@ -36,6 +40,9 @@ public class SystemController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private SystemDomainService systemDomainService;
|
private SystemDomainService systemDomainService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SystemOrganizationRepository systemOrganizationRepository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private OrgRequest orgRequest;
|
private OrgRequest orgRequest;
|
||||||
|
|
||||||
|
@ -127,4 +134,25 @@ public class SystemController {
|
||||||
organizationTicketClerk.getExtension());
|
organizationTicketClerk.getExtension());
|
||||||
return Result.Success(SUCCESS);
|
return Result.Success(SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation("查询所有公司信息")
|
||||||
|
@PostMapping("/organization/all/company")
|
||||||
|
public Result<List<SystemOrganizationVO>> queryAllCompanyInfo() {
|
||||||
|
List<SystemOrganizationVO> systemOrganizationVOList = systemOrganizationRepository.findByOrgLevelIsNull()
|
||||||
|
.stream()
|
||||||
|
.map(SystemOrganization::mapToVO)
|
||||||
|
.toList();
|
||||||
|
return Result.Success(SUCCESS, systemOrganizationVOList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("查询子部门信息")
|
||||||
|
@PostMapping("/organization/sub/org")
|
||||||
|
public Result<List<SystemOrganizationVO>> querySubOrgInfo(@RequestBody SystemOrganizationParam systemOrganizationParam) {
|
||||||
|
List<SystemOrganizationVO> systemOrganizationVOList = systemOrganizationRepository
|
||||||
|
.findByParentId(systemOrganizationParam.getId())
|
||||||
|
.stream()
|
||||||
|
.map(SystemOrganization::mapToVO)
|
||||||
|
.toList();
|
||||||
|
return Result.Success(SUCCESS, systemOrganizationVOList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
package com.chint.application.out;
|
package com.chint.application.system;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import com.chint.application.dtos.response.UserRes;
|
import com.chint.application.dtos.response.UserRes;
|
||||||
|
import com.chint.application.dtos.system.RoleOrgParam;
|
||||||
|
import com.chint.domain.aggregates.user.Role;
|
||||||
|
import com.chint.domain.aggregates.user.RoleUser;
|
||||||
import com.chint.domain.aggregates.user.User;
|
import com.chint.domain.aggregates.user.User;
|
||||||
import com.chint.domain.aggregates.user.UserDepartmentInfo;
|
import com.chint.domain.aggregates.user.UserDepartmentInfo;
|
||||||
|
import com.chint.domain.repository.RoleRepository;
|
||||||
|
import com.chint.domain.repository.RoleUserRepository;
|
||||||
import com.chint.domain.repository.UserRepository;
|
import com.chint.domain.repository.UserRepository;
|
||||||
import com.chint.infrastructure.util.BaseContext;
|
import com.chint.infrastructure.util.BaseContext;
|
||||||
import com.chint.infrastructure.util.Result;
|
import com.chint.infrastructure.util.Result;
|
||||||
|
@ -30,13 +35,41 @@ public class UserController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserHttpRequest userHttpRequest;
|
private UserHttpRequest userHttpRequest;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RoleUserRepository roleUserRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RoleRepository roleRepository;
|
||||||
|
|
||||||
@ApiOperation("根据Id查询用户信息")
|
@ApiOperation("根据Id查询用户信息")
|
||||||
@PostMapping("/query")
|
@PostMapping("/query")
|
||||||
public Result<UserRes> getUserByEmployeeNo() {
|
public Result<UserRes> getUserByEmployeeNo() {
|
||||||
User currentUser = BaseContext.getCurrentUser();
|
User currentUser = BaseContext.getCurrentUser().loadRoleOrg();
|
||||||
return Result.Success(SUCCESS, BeanUtil.copyProperties(currentUser, UserRes.class));
|
return Result.Success(SUCCESS, BeanUtil.copyProperties(currentUser, UserRes.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation("根据用户ID添加角色权限")
|
||||||
|
@PostMapping("/add/role")
|
||||||
|
public Result<String> addRoleUser(@RequestBody RoleOrgParam roleOrgParam) {
|
||||||
|
roleOrgParam.getRoleIdList().stream()
|
||||||
|
.map(it -> RoleUser.of(roleOrgParam.getUserId(), it))
|
||||||
|
.toList()
|
||||||
|
.forEach(it -> roleUserRepository.save(it));
|
||||||
|
return Result.Success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ApiOperation("编辑角色组织权限")
|
||||||
|
@PostMapping("/edit/role")
|
||||||
|
public Result<String> editRole(@RequestBody RoleOrgParam roleOrgParam) {
|
||||||
|
roleRepository.findById(roleOrgParam.getRoleId())
|
||||||
|
.ifPresentOrElse(
|
||||||
|
role -> roleRepository.save(role.updateWithParam(roleOrgParam)),
|
||||||
|
() -> roleRepository.save(Role.buildWithParam(roleOrgParam)
|
||||||
|
));
|
||||||
|
return Result.Success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation("根据Id查询用户信息")
|
@ApiOperation("根据Id查询用户信息")
|
||||||
@PostMapping("/sync/public")
|
@PostMapping("/sync/public")
|
|
@ -142,9 +142,6 @@ public class OrderDetail implements Serializable {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return this.orderEventList.isEmpty() ? null : this.orderEventList.get(this.orderEventList.size() - 1);
|
return this.orderEventList.isEmpty() ? null : this.orderEventList.get(this.orderEventList.size() - 1);
|
||||||
// .stream()
|
|
||||||
// .max(Comparator.comparingLong(OrderEvent::getOrderEventId))
|
|
||||||
// .orElseThrow(() -> new NotFoundException(NOT_FOUND));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<OrderEvent> getETAEvent() {
|
public Optional<OrderEvent> getETAEvent() {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package com.chint.domain.aggregates.system;
|
package com.chint.domain.aggregates.system;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import com.chint.application.dtos.SystemAnnouncementDTO;
|
import com.chint.application.dtos.system.SystemAnnouncementDTO;
|
||||||
import com.chint.application.dtos.SystemAnnouncementVO;
|
import com.chint.application.dtos.system.SystemAnnouncementVO;
|
||||||
import com.chint.domain.aggregates.user.User;
|
import com.chint.domain.aggregates.user.User;
|
||||||
import com.chint.infrastructure.util.BaseContext;
|
import com.chint.infrastructure.util.BaseContext;
|
||||||
import com.chint.infrastructure.util.DateTimeUtil;
|
import com.chint.infrastructure.util.DateTimeUtil;
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.chint.domain.aggregates.system;
|
package com.chint.domain.aggregates.system;
|
||||||
|
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import com.chint.domain.value_object.system.SystemOrganizationVO;
|
||||||
import com.chint.interfaces.rest.data_center.org.OrgSfResponse;
|
import com.chint.interfaces.rest.data_center.org.OrgSfResponse;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
|
@ -81,4 +83,8 @@ public class SystemOrganization implements Serializable {
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SystemOrganizationVO mapToVO() {
|
||||||
|
return BeanUtil.copyProperties(this, SystemOrganizationVO.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
package com.chint.domain.aggregates.user;
|
||||||
|
|
||||||
|
|
||||||
|
import com.chint.application.dtos.system.RoleOrgParam;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.relational.core.mapping.MappedCollection;
|
||||||
|
import org.springframework.data.relational.core.mapping.Table;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Table("role")
|
||||||
|
public class Role {
|
||||||
|
@Id
|
||||||
|
private Long id;
|
||||||
|
private String roleName;
|
||||||
|
private String roleDesc;
|
||||||
|
@MappedCollection(idColumn = "role_id", keyColumn = "role_key")
|
||||||
|
private List<RoleOrganization> roleOrganizationList;
|
||||||
|
|
||||||
|
public Role addRoleOrganization(RoleOrganization roleOrganization) {
|
||||||
|
if (roleOrganizationList == null) {
|
||||||
|
roleOrganizationList = new ArrayList<>();
|
||||||
|
}
|
||||||
|
for (RoleOrganization organization : roleOrganizationList) {
|
||||||
|
if (organization.getOrgId().equals(roleOrganization.getOrgId())) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
roleOrganizationList.add(roleOrganization);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Role updateWithParam(RoleOrgParam roleOrgParam) {
|
||||||
|
roleOrgParam.getOrgIdList().stream()
|
||||||
|
.map(it -> RoleOrganization.of(roleOrgParam.getRoleId(), it))
|
||||||
|
.toList()
|
||||||
|
.forEach(this::addRoleOrganization);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Role buildWithParam(RoleOrgParam roleOrgParam) {
|
||||||
|
Role role = new Role();
|
||||||
|
role.setRoleName(roleOrgParam.getRoleName());
|
||||||
|
role.setRoleDesc(roleOrgParam.getRoleDesc());
|
||||||
|
if(roleOrgParam.getRoleIdList() != null){
|
||||||
|
roleOrgParam.getOrgIdList().stream()
|
||||||
|
.map(it -> RoleOrganization.of(roleOrgParam.getRoleId(), it))
|
||||||
|
.toList()
|
||||||
|
.forEach(role::addRoleOrganization);
|
||||||
|
}
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.chint.domain.aggregates.user;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.relational.core.mapping.Table;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Table("role_organization")
|
||||||
|
public class RoleOrganization {
|
||||||
|
@Id
|
||||||
|
private Long id;
|
||||||
|
private Long roleId;
|
||||||
|
private Long orgId;
|
||||||
|
|
||||||
|
public static RoleOrganization of(Long roleId, Long orgId) {
|
||||||
|
RoleOrganization roleOrganization = new RoleOrganization();
|
||||||
|
roleOrganization.setRoleId(roleId);
|
||||||
|
roleOrganization.setOrgId(orgId);
|
||||||
|
return roleOrganization;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.chint.domain.aggregates.user;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.relational.core.mapping.Table;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Table("role_user")
|
||||||
|
public class RoleUser {
|
||||||
|
@Id
|
||||||
|
private Long id;
|
||||||
|
private Long userId;
|
||||||
|
private Long roleId;
|
||||||
|
|
||||||
|
public static RoleUser of(Long userId, Long roleId) {
|
||||||
|
RoleUser roleUser = new RoleUser();
|
||||||
|
roleUser.setUserId(userId);
|
||||||
|
roleUser.setRoleId(roleId);
|
||||||
|
return roleUser;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,11 +3,13 @@ package com.chint.domain.aggregates.user;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import com.auth0.jwt.interfaces.Claim;
|
import com.auth0.jwt.interfaces.Claim;
|
||||||
import com.auth0.jwt.interfaces.DecodedJWT;
|
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||||
|
import com.chint.application.commands.UserRoleCommand;
|
||||||
import com.chint.application.commands.UserSFCommand;
|
import com.chint.application.commands.UserSFCommand;
|
||||||
import com.chint.domain.aggregates.system.FsscSystem;
|
import com.chint.domain.aggregates.system.FsscSystem;
|
||||||
import com.chint.domain.exceptions.NotFoundException;
|
import com.chint.domain.exceptions.NotFoundException;
|
||||||
import com.chint.domain.value_object.UserLoginParam;
|
import com.chint.domain.value_object.UserLoginParam;
|
||||||
import com.chint.domain.value_object.UserVO;
|
import com.chint.domain.value_object.UserVO;
|
||||||
|
import com.chint.domain.value_object.system.SystemOrganizationVO;
|
||||||
import com.chint.infrastructure.constant.AuthMessageConstant;
|
import com.chint.infrastructure.constant.AuthMessageConstant;
|
||||||
import com.chint.infrastructure.echo_framework.command.Command;
|
import com.chint.infrastructure.echo_framework.command.Command;
|
||||||
import com.chint.infrastructure.util.BaseContext;
|
import com.chint.infrastructure.util.BaseContext;
|
||||||
|
@ -76,6 +78,10 @@ public class User implements Serializable {
|
||||||
private String workStatus;
|
private String workStatus;
|
||||||
@Transient
|
@Transient
|
||||||
private UserLoginParam userLoginParam;
|
private UserLoginParam userLoginParam;
|
||||||
|
@Transient
|
||||||
|
private List<String> roleOrgCodeList;
|
||||||
|
@Transient
|
||||||
|
private List<SystemOrganizationVO> roleOrgList;
|
||||||
|
|
||||||
public User loadInfoFromDept() {
|
public User loadInfoFromDept() {
|
||||||
if (this.userDepartmentInfoList == null || this.userDepartmentInfoList.isEmpty()) {
|
if (this.userDepartmentInfoList == null || this.userDepartmentInfoList.isEmpty()) {
|
||||||
|
@ -383,4 +389,9 @@ public class User implements Serializable {
|
||||||
this.setUserDepartmentInfoList(result);
|
this.setUserDepartmentInfoList(result);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public User loadRoleOrg() {
|
||||||
|
Command.of(UserRoleCommand.class).user(this).sendToQueue();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.chint.domain.repository;
|
||||||
|
|
||||||
|
|
||||||
|
import com.chint.domain.aggregates.user.Role;
|
||||||
|
|
||||||
|
import javax.swing.text.html.Option;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface RoleRepository {
|
||||||
|
Optional<Role> findById(Long id);
|
||||||
|
|
||||||
|
Role save(Role role);
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.chint.domain.repository;
|
||||||
|
|
||||||
|
import com.chint.domain.aggregates.user.RoleUser;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface RoleUserRepository {
|
||||||
|
List<RoleUser> findByUserId(Long userId);
|
||||||
|
|
||||||
|
RoleUser save(RoleUser roleUser);
|
||||||
|
}
|
|
@ -13,9 +13,14 @@ public interface SystemOrganizationRepository {
|
||||||
|
|
||||||
List<SystemOrganization> findAll();
|
List<SystemOrganization> findAll();
|
||||||
|
|
||||||
|
List<SystemOrganization> findByIdIn(List<Long> ids);
|
||||||
|
|
||||||
|
List<SystemOrganization> findByOrgLevelIsNull();
|
||||||
|
|
||||||
Optional<SystemOrganization> findByOrgCodeContaining(String orgCode);
|
Optional<SystemOrganization> findByOrgCodeContaining(String orgCode);
|
||||||
|
|
||||||
List<SystemOrganization> findByOrgCodeList(List<String> orgCode);
|
List<SystemOrganization> findByOrgCodeList(List<String> orgCode);
|
||||||
|
|
||||||
List<SystemOrganization> findByParentId(Long parentId);
|
List<SystemOrganization> findByParentId(Long parentId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,12 +28,12 @@ import com.chint.interfaces.rest.ctrip.dto.search.car.OrderFee;
|
||||||
import com.chint.interfaces.rest.ctrip.dto.search.flight.*;
|
import com.chint.interfaces.rest.ctrip.dto.search.flight.*;
|
||||||
import com.chint.interfaces.rest.ctrip.dto.search.hotel.HotelOrderInfoEntity;
|
import com.chint.interfaces.rest.ctrip.dto.search.hotel.HotelOrderInfoEntity;
|
||||||
import com.chint.interfaces.rest.ctrip.dto.search.hotel.RefundInfo;
|
import com.chint.interfaces.rest.ctrip.dto.search.hotel.RefundInfo;
|
||||||
|
import com.chint.interfaces.rest.data_center.user.UserHttpRequest;
|
||||||
import com.chint.interfaces.rest.ly.LYSearchRequest;
|
import com.chint.interfaces.rest.ly.LYSearchRequest;
|
||||||
import com.chint.interfaces.rest.ly.dto.search.response.car.CarDetailResponse;
|
import com.chint.interfaces.rest.ly.dto.search.response.car.CarDetailResponse;
|
||||||
import com.chint.interfaces.rest.ly.dto.search.response.filght.FlightOrderResponse;
|
import com.chint.interfaces.rest.ly.dto.search.response.filght.FlightOrderResponse;
|
||||||
import com.chint.interfaces.rest.ly.dto.search.response.hotel.HotelDetailResponse;
|
import com.chint.interfaces.rest.ly.dto.search.response.hotel.HotelDetailResponse;
|
||||||
import com.chint.interfaces.rest.ly.dto.search.response.train.TrainDetailResponse;
|
import com.chint.interfaces.rest.ly.dto.search.response.train.TrainDetailResponse;
|
||||||
import com.chint.interfaces.rest.data_center.user.UserHttpRequest;
|
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -59,12 +59,6 @@ public class OrderDomainService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private RouteRepository routeRepository;
|
private RouteRepository routeRepository;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserRepository userRepository;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private LocationRepository locationRepository;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RouteOrderFactory routeOrderFactory;
|
private RouteOrderFactory routeOrderFactory;
|
||||||
|
|
||||||
|
@ -74,18 +68,6 @@ public class OrderDomainService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private OrderDetailRepository orderDetailRepository;
|
private OrderDetailRepository orderDetailRepository;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserHttpRequest userHttpRequest;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private BPMParamFactory bpmParamFactory;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private BPMRequest bpmRequest;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private LegRepository legRepository;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LegEventFactory legEventFactory;
|
private LegEventFactory legEventFactory;
|
||||||
|
|
||||||
|
@ -98,12 +80,6 @@ public class OrderDomainService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private LYSearchRequest lySearchRequest;
|
private LYSearchRequest lySearchRequest;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JdbcOrderDetailRepository jdbcOrderDetailRepository;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JdbcLegRepository jdbcLegRepository;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private BPMOrderDomainService bpmOrderDomainService;
|
private BPMOrderDomainService bpmOrderDomainService;
|
||||||
|
|
||||||
|
@ -183,55 +159,77 @@ public class OrderDomainService {
|
||||||
OrderDetail orderDetail = command.getOrderDetail();
|
OrderDetail orderDetail = command.getOrderDetail();
|
||||||
String outStatus = command.getOutStatus();
|
String outStatus = command.getOutStatus();
|
||||||
Integer orderEventType = command.getOrderEventType();
|
Integer orderEventType = command.getOrderEventType();
|
||||||
OrderEvent event = orderDetailFactory.createEvent(orderEventType,
|
OrderEvent event = orderDetailFactory.createEvent(orderEventType, outStatus);
|
||||||
outStatus);
|
|
||||||
if (orderEventType.equals(ORDER_EVENT_ETA) ||
|
if (isSpecialEventType(orderEventType)) {
|
||||||
orderEventType.equals(ORDER_EVENT_CHANGE) ||
|
|
||||||
orderEventType.equals(ORDER_EVENT_REFUND)) {
|
|
||||||
event.setExtension(command.getExtension());
|
event.setExtension(command.getExtension());
|
||||||
}
|
}
|
||||||
|
|
||||||
orderDetail.addOrderEvent(event);
|
orderDetail.addOrderEvent(event);
|
||||||
|
reCheckOrderETA(event, orderDetail);
|
||||||
orderDetailRepository.save(orderDetail);
|
orderDetailRepository.save(orderDetail);
|
||||||
|
|
||||||
if (orderEventType.equals(ORDER_EVENT_ETA) ||
|
if (isSpecialEventType(orderEventType)) {
|
||||||
|
handleSpecialEvent(orderDetail, command, orderEventType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSpecialEventType(Integer orderEventType) {
|
||||||
|
return orderEventType.equals(ORDER_EVENT_ETA) ||
|
||||||
orderEventType.equals(ORDER_EVENT_CHANGE) ||
|
orderEventType.equals(ORDER_EVENT_CHANGE) ||
|
||||||
orderEventType.equals(ORDER_EVENT_REFUND)) {
|
orderEventType.equals(ORDER_EVENT_REFUND);
|
||||||
//这里如果发现事件的状态为ORDER_EVENT_ETA
|
}
|
||||||
//需要根据发送审批给bpm
|
|
||||||
//根据订单类型获取不同的订单扩展明细
|
|
||||||
orderDetail.getExtensionDataByProductType();
|
|
||||||
Command.of(BPMAuditCommand.class)
|
|
||||||
.operationType(orderEventType)
|
|
||||||
.orderNo(orderDetail.getOrderNo())
|
|
||||||
.productType(orderDetail.getProductType())
|
|
||||||
.extensionData(orderDetail)
|
|
||||||
.reason(command.getExtension())
|
|
||||||
.sendToQueue();
|
|
||||||
|
|
||||||
if (orderDetail.getSupplierName().equals(SUPPLIER_C_TRIP)) {
|
private void handleSpecialEvent(OrderDetail orderDetail, OrderStatusChangeCommand command, Integer orderEventType) {
|
||||||
if (!orderEventType.equals(ORDER_EVENT_ETA) && orderDetail.getProductType().equals(LEG_TYPE_AIRPLANE)) {
|
orderDetail.getExtensionDataByProductType();
|
||||||
cTripFlightRefundAndChangeOrder(orderDetail.getOrderNo());
|
sendBPMAuditCommand(orderDetail, command, orderEventType);
|
||||||
}
|
|
||||||
if (orderDetail.getProductType().equals(LEG_TYPE_HOTEL)) {
|
|
||||||
cTripHotelRefundAndChangeOrder(orderDetail.getOrderNo());
|
|
||||||
}
|
|
||||||
if (!orderEventType.equals(ORDER_EVENT_ETA) && orderDetail.getProductType().equals(LEG_TYPE_TAXI)) {
|
|
||||||
cTripCarRefundChangeOrder(orderDetail.getOrderNo());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (orderDetail.getSupplierName().equals(SUPPLIER_L_Y)) {
|
String supplierName = orderDetail.getSupplierName();
|
||||||
if (!orderEventType.equals(ORDER_EVENT_ETA) && orderDetail.getProductType().equals(LEG_TYPE_TRAIN)) {
|
Integer productType = orderDetail.getProductType();
|
||||||
lyTrainRefundGenerate(orderDetail.getOrderNo());
|
|
||||||
}
|
if (SUPPLIER_C_TRIP.equals(supplierName)) {
|
||||||
if (!orderEventType.equals(ORDER_EVENT_ETA) && orderDetail.getProductType().equals(LEG_TYPE_HOTEL)) {
|
handleCTripEvents(orderDetail, orderEventType, productType);
|
||||||
lyHotelRefundGenerate(orderDetail.getOrderNo());
|
} else if (SUPPLIER_L_Y.equals(supplierName)) {
|
||||||
}
|
handleLYEvents(orderDetail, orderEventType, productType);
|
||||||
if (!orderEventType.equals(ORDER_EVENT_ETA) && orderDetail.getProductType().equals(LEG_TYPE_TAXI)) {
|
}
|
||||||
lyCarRefundGenerate(orderDetail.getOrderNo());
|
}
|
||||||
}
|
|
||||||
|
private void sendBPMAuditCommand(OrderDetail orderDetail, OrderStatusChangeCommand command, Integer orderEventType) {
|
||||||
|
Command.of(BPMAuditCommand.class)
|
||||||
|
.operationType(orderEventType)
|
||||||
|
.orderNo(orderDetail.getOrderNo())
|
||||||
|
.productType(orderDetail.getProductType())
|
||||||
|
.extensionData(orderDetail)
|
||||||
|
.reason(command.getExtension())
|
||||||
|
.sendToQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleCTripEvents(OrderDetail orderDetail, Integer orderEventType, Integer productType) {
|
||||||
|
String orderNo = orderDetail.getOrderNo();
|
||||||
|
if (ORDER_EVENT_ETA != orderEventType) {
|
||||||
|
if (LEG_TYPE_AIRPLANE == productType) {
|
||||||
|
cTripFlightRefundAndChangeOrder(orderNo);
|
||||||
|
} else if (LEG_TYPE_TAXI == productType) {
|
||||||
|
cTripCarRefundChangeOrder(orderNo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (LEG_TYPE_HOTEL == productType) {
|
||||||
|
cTripHotelRefundAndChangeOrder(orderNo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleLYEvents(OrderDetail orderDetail, Integer orderEventType, Integer productType) {
|
||||||
|
String orderNo = orderDetail.getOrderNo();
|
||||||
|
if (ORDER_EVENT_ETA != (orderEventType)) {
|
||||||
|
if (LEG_TYPE_TRAIN == productType) {
|
||||||
|
lyTrainRefundGenerate(orderNo);
|
||||||
|
} else if (LEG_TYPE_TAXI == productType) {
|
||||||
|
lyCarRefundGenerate(orderNo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (LEG_TYPE_HOTEL == productType) {
|
||||||
|
lyHotelRefundGenerate(orderNo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ListenTo(command = "BPMAuditCommand", order = 0)
|
@ListenTo(command = "BPMAuditCommand", order = 0)
|
||||||
|
@ -431,4 +429,45 @@ public class OrderDomainService {
|
||||||
}
|
}
|
||||||
return routeOrder;
|
return routeOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private OrderDetail reCheckOrderETA(OrderEvent orderEvent, OrderDetail orderDetail) {
|
||||||
|
if (!orderEvent.getEventType().equals(ORDER_EVENT_ETA)) {
|
||||||
|
return orderDetail;
|
||||||
|
}
|
||||||
|
Integer productType = orderDetail.getProductType();
|
||||||
|
switch (productType) {
|
||||||
|
case LEG_TYPE_TRAIN -> {
|
||||||
|
TrainOrderDetail trainOrderDetail = orderDetail.getTrainOrderDetail();
|
||||||
|
if (trainOrderDetail != null) {
|
||||||
|
trainOrderDetail.setOverStandard("是");
|
||||||
|
trainOrderDetail.setOverStandardReason(orderEvent.getExtension());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case LEG_TYPE_AIRPLANE -> {
|
||||||
|
FlightOrderDetail flightOrderDetail = orderDetail.getFlightOrderDetail();
|
||||||
|
if (flightOrderDetail != null) {
|
||||||
|
flightOrderDetail.setOverStandard("是");
|
||||||
|
flightOrderDetail.setOverStandardReason(orderEvent.getExtension());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case LEG_TYPE_HOTEL -> {
|
||||||
|
HotelOrderDetail hotelOrderDetail = orderDetail.getHotelOrderDetail();
|
||||||
|
if (hotelOrderDetail != null) {
|
||||||
|
hotelOrderDetail.setOverStandard("是");
|
||||||
|
hotelOrderDetail.setOverStandardReason(orderEvent.getExtension());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case LEG_TYPE_TAXI -> {
|
||||||
|
CarOrderDetail carOrderDetail = orderDetail.getCarOrderDetail();
|
||||||
|
if (carOrderDetail != null) {
|
||||||
|
carOrderDetail.setOverStandard("是");
|
||||||
|
carOrderDetail.setOverStandardReason(orderEvent.getExtension());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return orderDetail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,22 @@
|
||||||
package com.chint.domain.service;
|
package com.chint.domain.service;
|
||||||
|
|
||||||
|
import com.chint.application.commands.UserRoleCommand;
|
||||||
import com.chint.application.dtos.OrganizationTicketClerk;
|
import com.chint.application.dtos.OrganizationTicketClerk;
|
||||||
import com.chint.domain.aggregates.order.order_record.OrderBaseRecord;
|
import com.chint.domain.aggregates.order.order_record.OrderBaseRecord;
|
||||||
import com.chint.domain.aggregates.system.AccountCompany;
|
import com.chint.domain.aggregates.system.AccountCompany;
|
||||||
import com.chint.domain.aggregates.system.SystemCode;
|
import com.chint.domain.aggregates.system.SystemCode;
|
||||||
import com.chint.domain.aggregates.system.SystemOrganization;
|
import com.chint.domain.aggregates.system.SystemOrganization;
|
||||||
import com.chint.domain.aggregates.system.SystemOrganizationExtension;
|
import com.chint.domain.aggregates.system.SystemOrganizationExtension;
|
||||||
|
import com.chint.domain.aggregates.user.RoleOrganization;
|
||||||
|
import com.chint.domain.aggregates.user.RoleUser;
|
||||||
|
import com.chint.domain.aggregates.user.User;
|
||||||
import com.chint.domain.exceptions.NotFoundException;
|
import com.chint.domain.exceptions.NotFoundException;
|
||||||
import com.chint.domain.repository.AccountCompanyRepository;
|
import com.chint.domain.repository.*;
|
||||||
import com.chint.domain.repository.SystemCodeRepository;
|
import com.chint.infrastructure.echo_framework.annotation.ListenTo;
|
||||||
import com.chint.domain.repository.SystemOrganizationRepository;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -33,6 +37,12 @@ public class SystemDomainService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private SystemOrganizationRepository systemOrganizationRepository;
|
private SystemOrganizationRepository systemOrganizationRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RoleUserRepository roleUserRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RoleRepository roleRepository;
|
||||||
|
|
||||||
public boolean checkSystemCode(String sysCode) {
|
public boolean checkSystemCode(String sysCode) {
|
||||||
boolean b = systemCodeRepository.findBySysCode(sysCode) != null;
|
boolean b = systemCodeRepository.findBySysCode(sysCode) != null;
|
||||||
if (!b) {
|
if (!b) {
|
||||||
|
@ -147,4 +157,46 @@ public class SystemDomainService {
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ListenTo(command = "UserRoleCommand", order = 0)
|
||||||
|
public void loadUserRole(UserRoleCommand command) {
|
||||||
|
User user = command.getUser();
|
||||||
|
List<RoleUser> byUserId = roleUserRepository.findByUserId(user.getUserId());
|
||||||
|
List<Long> orgListId = byUserId.stream().flatMap(it ->
|
||||||
|
roleRepository
|
||||||
|
.findById(it.getRoleId())
|
||||||
|
.stream()
|
||||||
|
.flatMap(role -> role.getRoleOrganizationList().stream())
|
||||||
|
.map(RoleOrganization::getOrgId)
|
||||||
|
).distinct().toList();
|
||||||
|
|
||||||
|
// 获取所有的 SystemOrganization
|
||||||
|
List<SystemOrganization> rootOrganizations = systemOrganizationRepository.findByIdIn(orgListId);
|
||||||
|
|
||||||
|
// 展开所有的 SystemOrganization
|
||||||
|
List<SystemOrganization> allOrganizations = new ArrayList<>();
|
||||||
|
rootOrganizations.forEach(rootOrg -> expandOrganizations(rootOrg, allOrganizations));
|
||||||
|
|
||||||
|
// 设置用户的角色组织列表
|
||||||
|
user.setRoleOrgCodeList(
|
||||||
|
allOrganizations.stream()
|
||||||
|
.map(SystemOrganization::getOrgShortCode)
|
||||||
|
.distinct()
|
||||||
|
.toList()
|
||||||
|
);
|
||||||
|
user.setRoleOrgList(
|
||||||
|
allOrganizations.stream()
|
||||||
|
.map(SystemOrganization::mapToVO)
|
||||||
|
.distinct()
|
||||||
|
.toList()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void expandOrganizations(SystemOrganization org, List<SystemOrganization> allOrganizations) {
|
||||||
|
queryChild(org); // 查询子组织
|
||||||
|
allOrganizations.add(org); // 添加当前组织到列表
|
||||||
|
for (SystemOrganization child : org.getChildOrganizationList()) {
|
||||||
|
expandOrganizations(child, allOrganizations); // 递归展开子组织
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.chint.domain.value_object.system;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SystemOrganizationVO {
|
||||||
|
private Long id;
|
||||||
|
private String orgCode;
|
||||||
|
private String orgShortCode;
|
||||||
|
private String orgName;
|
||||||
|
private String orgEnName;
|
||||||
|
private Long parentId;
|
||||||
|
private String parentOrgCode;
|
||||||
|
private String parentOrgName;
|
||||||
|
private String parentOrgEnName;
|
||||||
|
private String costCenter;
|
||||||
|
private String orgLevel;
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.chint.infrastructure.repository;
|
||||||
|
|
||||||
|
import com.chint.domain.aggregates.user.Role;
|
||||||
|
import com.chint.domain.repository.RoleRepository;
|
||||||
|
import com.chint.infrastructure.repository.cache.CacheRoleRepository;
|
||||||
|
import com.chint.infrastructure.repository.jdbc.JdbcRoleRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class RoleRepositoryImpl implements RoleRepository {
|
||||||
|
@Autowired
|
||||||
|
private JdbcRoleRepository jdbcRoleRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CacheRoleRepository cacheRoleRepository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Role> findById(Long id) {
|
||||||
|
if (id == null) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
Optional<Role> fromCache = cacheRoleRepository.getFromCache(id, Optional.empty());
|
||||||
|
if (fromCache.isPresent()) {
|
||||||
|
return fromCache;
|
||||||
|
} else {
|
||||||
|
return cacheRoleRepository.getFromCache(id, jdbcRoleRepository.findById(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Role save(Role role) {
|
||||||
|
Long id = role.getId();
|
||||||
|
if(id != null){
|
||||||
|
cacheRoleRepository.evict(id);
|
||||||
|
}
|
||||||
|
return jdbcRoleRepository.save(role);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.chint.infrastructure.repository;
|
||||||
|
|
||||||
|
import com.chint.domain.aggregates.user.RoleUser;
|
||||||
|
import com.chint.domain.repository.RoleUserRepository;
|
||||||
|
import com.chint.infrastructure.repository.jdbc.JdbcRoleUserRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class RoleUserRepositoryImpl implements RoleUserRepository {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JdbcRoleUserRepository jdbcRoleUserRepository;
|
||||||
|
|
||||||
|
@Cacheable(value = "RoleUser", key = "#userId")
|
||||||
|
@Override
|
||||||
|
public List<RoleUser> findByUserId(Long userId) {
|
||||||
|
return jdbcRoleUserRepository.findByUserId(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@CacheEvict(value = "RoleUser", key = "#roleUser.userId")
|
||||||
|
@Override
|
||||||
|
public RoleUser save(RoleUser roleUser) {
|
||||||
|
return jdbcRoleUserRepository.save(roleUser);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package com.chint.infrastructure.repository;
|
||||||
|
|
||||||
import com.chint.domain.aggregates.system.SystemOrganization;
|
import com.chint.domain.aggregates.system.SystemOrganization;
|
||||||
import com.chint.domain.repository.SystemOrganizationRepository;
|
import com.chint.domain.repository.SystemOrganizationRepository;
|
||||||
|
import com.chint.infrastructure.repository.cache.CacheSystemOrganizationRepository;
|
||||||
import com.chint.infrastructure.repository.jdbc.JdbcSystemOrganizationRepository;
|
import com.chint.infrastructure.repository.jdbc.JdbcSystemOrganizationRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
@ -16,6 +17,9 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos
|
||||||
@Autowired
|
@Autowired
|
||||||
private JdbcSystemOrganizationRepository jdbcSystemOrganizationRepository;
|
private JdbcSystemOrganizationRepository jdbcSystemOrganizationRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CacheSystemOrganizationRepository cacheSystemOrganizationRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveAll(List<SystemOrganization> systemOrganizationList) {
|
public void saveAll(List<SystemOrganization> systemOrganizationList) {
|
||||||
for (SystemOrganization systemOrganization : systemOrganizationList) {
|
for (SystemOrganization systemOrganization : systemOrganizationList) {
|
||||||
|
@ -30,7 +34,10 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SystemOrganization save(SystemOrganization systemOrganization) {
|
public SystemOrganization save(SystemOrganization systemOrganization) {
|
||||||
return jdbcSystemOrganizationRepository.save(systemOrganization);
|
cacheSystemOrganizationRepository.cacheEvict(systemOrganization); // 先清理旧缓存
|
||||||
|
jdbcSystemOrganizationRepository.save(systemOrganization);
|
||||||
|
cacheSystemOrganizationRepository.cacheEvictIdsByParentId(systemOrganization.getParentId());
|
||||||
|
return cacheSystemOrganizationRepository.cache(systemOrganization);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -41,20 +48,55 @@ public class SystemOrganizationRepositoryImpl implements SystemOrganizationRepos
|
||||||
return systemOrganizationList;
|
return systemOrganizationList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SystemOrganization> findByIdIn(List<Long> ids) {
|
||||||
|
List<SystemOrganization> fromCacheByIdIn = cacheSystemOrganizationRepository.getFromCacheByIdIn(ids);
|
||||||
|
List<Long> fromCacheOrg = fromCacheByIdIn.stream().map(SystemOrganization::getId).toList();
|
||||||
|
List<Long> list = ids.stream().filter(it -> !fromCacheOrg.contains(it)).toList();
|
||||||
|
if (!list.isEmpty()) {
|
||||||
|
List<SystemOrganization> fromDBByIdIn = jdbcSystemOrganizationRepository.findByIdIn(list);
|
||||||
|
fromDBByIdIn.forEach(it -> cacheSystemOrganizationRepository.cache(it)); // 更新缓存
|
||||||
|
fromCacheByIdIn.addAll(fromDBByIdIn);
|
||||||
|
}
|
||||||
|
return fromCacheByIdIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SystemOrganization> findByOrgLevelIsNull() {
|
||||||
|
return jdbcSystemOrganizationRepository.findByOrgLevelIsNullOrOrgLevel("").stream()
|
||||||
|
.peek(systemOrganization -> cacheSystemOrganizationRepository.cache(systemOrganization)) // 更新缓存
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<SystemOrganization> findByOrgCodeContaining(String orgCode) {
|
public Optional<SystemOrganization> findByOrgCodeContaining(String orgCode) {
|
||||||
return jdbcSystemOrganizationRepository.findByOrgCodeContaining(orgCode).stream().findFirst();
|
return jdbcSystemOrganizationRepository.findByOrgCodeContaining(orgCode).stream()
|
||||||
|
.peek(systemOrganization -> cacheSystemOrganizationRepository.cache(systemOrganization)) // 更新缓存
|
||||||
|
.findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SystemOrganization> findByOrgCodeList(List<String> orgCode) {
|
public List<SystemOrganization> findByOrgCodeList(List<String> orgCode) {
|
||||||
return jdbcSystemOrganizationRepository.findByOrgShortCodeIn(orgCode);
|
return jdbcSystemOrganizationRepository.findByOrgShortCodeIn(orgCode).stream()
|
||||||
|
.peek(systemOrganization -> cacheSystemOrganizationRepository.cache(systemOrganization)) // 更新缓存
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SystemOrganization> findByParentId(Long parentId) {
|
public List<SystemOrganization> findByParentId(Long parentId) {
|
||||||
return jdbcSystemOrganizationRepository.findByParentId(parentId);
|
List<Long> idsFromCacheByParentId = cacheSystemOrganizationRepository.getIdsFromCacheByParentId(parentId, null);
|
||||||
|
List<SystemOrganization> list;
|
||||||
|
if (idsFromCacheByParentId == null) {
|
||||||
|
list = jdbcSystemOrganizationRepository.findByParentId(parentId).stream()
|
||||||
|
.peek(systemOrganization -> cacheSystemOrganizationRepository.cache(systemOrganization)) // 更新缓存
|
||||||
|
.toList();
|
||||||
|
cacheSystemOrganizationRepository.cacheEvictIdsByParentId(parentId);
|
||||||
|
List<Long> ids = list.stream().map(SystemOrganization::getId).toList();
|
||||||
|
cacheSystemOrganizationRepository.getIdsFromCacheByParentId(parentId, ids);
|
||||||
|
} else {
|
||||||
|
list = cacheSystemOrganizationRepository.getFromCacheByIdIn(idsFromCacheByParentId);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
22
src/main/java/com/chint/infrastructure/repository/cache/CacheRoleRepository.java
vendored
Normal file
22
src/main/java/com/chint/infrastructure/repository/cache/CacheRoleRepository.java
vendored
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package com.chint.infrastructure.repository.cache;
|
||||||
|
|
||||||
|
import com.chint.domain.aggregates.user.Role;
|
||||||
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class CacheRoleRepository {
|
||||||
|
|
||||||
|
|
||||||
|
@Cacheable(value = "Role", key = "#id")
|
||||||
|
public Optional<Role> getFromCache(Long id, Optional<Role> role) {
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
|
||||||
|
@CacheEvict(value = "Role", key = "#id")
|
||||||
|
public void evict(Long id) {
|
||||||
|
}
|
||||||
|
}
|
43
src/main/java/com/chint/infrastructure/repository/cache/CacheSystemOrganizationRepository.java
vendored
Normal file
43
src/main/java/com/chint/infrastructure/repository/cache/CacheSystemOrganizationRepository.java
vendored
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
package com.chint.infrastructure.repository.cache;
|
||||||
|
|
||||||
|
|
||||||
|
import com.chint.domain.aggregates.system.SystemOrganization;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class CacheSystemOrganizationRepository {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate<String, SystemOrganization> redisTemplate;
|
||||||
|
|
||||||
|
public List<SystemOrganization> getFromCacheByIdIn(List<Long> ids) {
|
||||||
|
List<String> routeOrderKeys = ids.stream().map(id -> "SystemOrganization::" + id).toList();
|
||||||
|
return redisTemplate.opsForValue().multiGet(routeOrderKeys);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Cacheable(value = "SystemOrganization", key = "#systemOrganization.id")
|
||||||
|
public SystemOrganization cache(SystemOrganization systemOrganization) {
|
||||||
|
return systemOrganization;
|
||||||
|
}
|
||||||
|
|
||||||
|
@CacheEvict(value = "SystemOrganization", key = "#systemOrganization.id")
|
||||||
|
public void cacheEvict(SystemOrganization systemOrganization) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Cacheable(value = "SystemOrganization::ParentId", key = "#parentId")
|
||||||
|
// 新增方法:根据 parentId 从缓存中获取子组织的 ID 列表
|
||||||
|
public List<Long> getIdsFromCacheByParentId(Long parentId, List<Long> ids) {
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增方法:根据 parentId 清除缓存中子组织的 ID 列表
|
||||||
|
@CacheEvict(value = "SystemOrganization::ParentId", key = "#parentId")
|
||||||
|
public void cacheEvictIdsByParentId(Long parentId) {
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.chint.infrastructure.repository.jdbc;
|
||||||
|
|
||||||
|
import com.chint.domain.aggregates.standards.Ranks;
|
||||||
|
import com.chint.domain.aggregates.user.Role;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface JdbcRoleRepository extends CrudRepository<Role, Long> {
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.chint.infrastructure.repository.jdbc;
|
||||||
|
|
||||||
|
import com.chint.domain.aggregates.user.RoleUser;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface JdbcRoleUserRepository extends CrudRepository<RoleUser, Long> {
|
||||||
|
|
||||||
|
List<RoleUser> findByUserId(Long userId);
|
||||||
|
}
|
|
@ -12,5 +12,7 @@ public interface JdbcSystemOrganizationRepository extends CrudRepository<SystemO
|
||||||
List<SystemOrganization> findByOrgCodeContaining(String orgCode);
|
List<SystemOrganization> findByOrgCodeContaining(String orgCode);
|
||||||
List<SystemOrganization> findByOrgCode(String orgCode);
|
List<SystemOrganization> findByOrgCode(String orgCode);
|
||||||
List<SystemOrganization> findByParentId(Long parentId);
|
List<SystemOrganization> findByParentId(Long parentId);
|
||||||
|
List<SystemOrganization> findByOrgLevelIsNullOrOrgLevel(String orgLevel);
|
||||||
List<SystemOrganization> findByOrgShortCodeIn(Collection<String> orgCode);
|
List<SystemOrganization> findByOrgShortCodeIn(Collection<String> orgCode);
|
||||||
|
List<SystemOrganization> findByIdIn(Collection<Long> id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,7 +246,7 @@ public class CTripTest {
|
||||||
@Test
|
@Test
|
||||||
void search() {
|
void search() {
|
||||||
BaseContext.setCurrentUser(user);
|
BaseContext.setCurrentUser(user);
|
||||||
SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("31900510524");
|
SearchOrderResponse response = orderSearchRequest.searchOrderResponseByOrderId("31791272980");
|
||||||
System.out.println(response);
|
System.out.println(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -291,7 +291,7 @@ class RouteApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void loginSign() {
|
void loginSign() {
|
||||||
String sfno = "0001018592";
|
String sfno = "060726001";
|
||||||
String syscode = "FSSC";
|
String syscode = "FSSC";
|
||||||
String billcode = "CLSQ240225000099";
|
String billcode = "CLSQ240225000099";
|
||||||
String companycode = "正泰集团股份有限公司";
|
String companycode = "正泰集团股份有限公司";
|
||||||
|
@ -302,7 +302,7 @@ class RouteApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void loginSignProd() {
|
void loginSignProd() {
|
||||||
String sfno = "180605039";
|
String sfno = "060726001";
|
||||||
String syscode = "FSSC";
|
String syscode = "FSSC";
|
||||||
String billcode = "CLSQ240225000099";
|
String billcode = "CLSQ240225000099";
|
||||||
String companycode = "正泰集团股份有限公司";
|
String companycode = "正泰集团股份有限公司";
|
||||||
|
@ -310,10 +310,6 @@ class RouteApplicationTests {
|
||||||
String key = "ZhengTaiRoute";
|
String key = "ZhengTaiRoute";
|
||||||
String s = Digest.md5(sfno + syscode + billcode + companycode + key + timespan);
|
String s = Digest.md5(sfno + syscode + billcode + companycode + key + timespan);
|
||||||
System.out.println(s);
|
System.out.println(s);
|
||||||
// log.info("info");
|
|
||||||
// log.trace("trace");
|
|
||||||
// log.trace("trace");
|
|
||||||
// log.trace("trace");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
// @Test
|
||||||
|
|
Loading…
Reference in New Issue