Commit 5404a7a5 authored by 王向伟's avatar 王向伟

多对多测试

parent b92d5ab1
...@@ -5,8 +5,6 @@ import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserStatus; ...@@ -5,8 +5,6 @@ import cn.quantgroup.cashloanflowboss.api.user.dictionary.UserStatus;
import cn.quantgroup.cashloanflowboss.api.user.entity.User; import cn.quantgroup.cashloanflowboss.api.user.entity.User;
import cn.quantgroup.cashloanflowboss.api.user.model.UserInfo; import cn.quantgroup.cashloanflowboss.api.user.model.UserInfo;
import cn.quantgroup.cashloanflowboss.api.user.service.UserService; import cn.quantgroup.cashloanflowboss.api.user.service.UserService;
import cn.quantgroup.cashloanflowboss.api.user.service.UserServiceImpl;
import cn.quantgroup.cashloanflowboss.core.asserts.Assert;
import cn.quantgroup.cashloanflowboss.core.base.Tuple; import cn.quantgroup.cashloanflowboss.core.base.Tuple;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationDictionary; import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationDictionary;
import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus; import cn.quantgroup.cashloanflowboss.core.dictionary.ApplicationStatus;
......
package cn.quantgroup.cashloanflowboss.api.manytomany;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import javax.persistence.*;
import java.util.List;
/**
* @author Wang Xiangwei
* @version 2020/3/10
*/
@Data
@Entity
@Table(name = "student")
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "name")
private String name;
@ManyToMany(cascade = { CascadeType.MERGE })
@JsonIgnore
@JoinTable(name = "student_teacher", joinColumns = { @JoinColumn(name = "student_id", referencedColumnName = "id") }, inverseJoinColumns = {
@JoinColumn(name = "teacher_id", referencedColumnName = "id") })
private List<Teacher> teachers;
}
package cn.quantgroup.cashloanflowboss.api.manytomany;
import cn.quantgroup.cashloanflowboss.core.persistence.CashLoanFlowBossPubConfDataSource;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* Created by WeiWei on 2019/7/22.
*/
@CashLoanFlowBossPubConfDataSource
@Repository
public interface StudentRepository extends JpaRepository<Student, Long> {
}
package cn.quantgroup.cashloanflowboss.api.manytomany;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import javax.persistence.*;
import java.util.List;
/**
* @author Wang Xiangwei
* @version 2020/3/10
*/
@Data
@Entity
@Table(name = "teacher")
public class Teacher {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "name")
private String name;
@ManyToMany(cascade = { CascadeType.MERGE })
@JsonIgnore
@JoinTable(name = "student_teacher", joinColumns = { @JoinColumn(name = "teacher_id", referencedColumnName = "id") }, inverseJoinColumns = {
@JoinColumn(name = "student_id", referencedColumnName = "id") })
private List<Student> students;
}
package cn.quantgroup.cashloanflowboss.api.manytomany;
import cn.quantgroup.cashloanflowboss.core.persistence.CashLoanFlowBossPubConfDataSource;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* Created by WeiWei on 2019/7/22.
*/
@CashLoanFlowBossPubConfDataSource
@Repository
public interface TeacherRepository extends JpaRepository<Teacher, Long> {
}
package cn.quantgroup.cashloanflowboss.api.manytomany;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Random;
/**
* @author Wang Xiangwei
* @version 2020/3/10
*/
@RestController
@RequestMapping("/test")
public class TestController123 {
@Autowired
private StudentRepository studentRepository;
@Autowired
private TeacherRepository teacherRepository;
@GetMapping("/add/teacher/relation/{id}")
public String test1(@PathVariable Long id){
Student one = studentRepository.findOne(id);
List<Teacher> all = teacherRepository.findAll();
one.setTeachers(all);
studentRepository.save(one);
return "www";
}
@GetMapping("/del/student/{id}")
public String test2(@PathVariable Long id){
studentRepository.delete(id);
return "www";
}
@GetMapping("/del/teacher/{id}")
public String test3(@PathVariable Long id){
teacherRepository.delete(id);
return "www";
}
@GetMapping("/add/student")
public String test4(){
Student student = new Student();
Random random = new Random();
student.setName(random.nextInt()+"");
studentRepository.save(student);
return "ww";
}
@GetMapping("/add/teacher")
public String test5(){
Teacher student = new Teacher();
Random random = new Random();
student.setName(random.nextInt()+"");
teacherRepository.save(student);
return "ww";
}
@GetMapping("/add/student/relation/{id}")
public String test6(@PathVariable Long id){
List<Student> all = studentRepository.findAll();
Teacher one = teacherRepository.findOne(id);
one.setStudents(all);
teacherRepository.save(one);
return "ww";
}
}
package cn.quantgroup.cashloanflowboss.api.mapping;
import lombok.Data;
import javax.persistence.*;
/**
* @author Wang Xiangwei
* @version 2020/3/11
*/
@Data
@Entity
@Table(name = "user_role_mapping")
public class UserRoleMapping {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "user_id")
private Long userId;
@Column(name = "role_id")
private Long roleId;
}
package cn.quantgroup.cashloanflowboss.api.mapping;
import cn.quantgroup.cashloanflowboss.core.persistence.CashLoanFlowBossPubConfDataSource;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.stereotype.Repository;
import javax.transaction.Transactional;
import java.util.List;
/**
* Created by WeiWei on 2019/7/22.
*/
@CashLoanFlowBossPubConfDataSource
@Repository
public interface UserRoleMappingRepository extends JpaRepository<UserRoleMapping, Long> {
List<UserRoleMapping> findAllByRoleId(Long roleId);
@Transactional
void deleteAllByRoleId(Long roleId);
}
package cn.quantgroup.cashloanflowboss.api.role.service; package cn.quantgroup.cashloanflowboss.api.role.service;
import cn.quantgroup.cashloanflowboss.api.mapping.UserRoleMapping;
import cn.quantgroup.cashloanflowboss.api.permissionmodule.entity.Permission; import cn.quantgroup.cashloanflowboss.api.permissionmodule.entity.Permission;
import cn.quantgroup.cashloanflowboss.api.permissionmodule.repository.PermissionRepository; import cn.quantgroup.cashloanflowboss.api.permissionmodule.repository.PermissionRepository;
import cn.quantgroup.cashloanflowboss.api.role.entity.Role; import cn.quantgroup.cashloanflowboss.api.role.entity.Role;
...@@ -8,6 +9,7 @@ import cn.quantgroup.cashloanflowboss.api.role.model.RoleModelVo; ...@@ -8,6 +9,7 @@ import cn.quantgroup.cashloanflowboss.api.role.model.RoleModelVo;
import cn.quantgroup.cashloanflowboss.api.role.model.RoleQueryModel; import cn.quantgroup.cashloanflowboss.api.role.model.RoleQueryModel;
import cn.quantgroup.cashloanflowboss.api.role.repository.RoleRepository; import cn.quantgroup.cashloanflowboss.api.role.repository.RoleRepository;
import cn.quantgroup.cashloanflowboss.core.base.Result; import cn.quantgroup.cashloanflowboss.core.base.Result;
import cn.quantgroup.cashloanflowboss.api.mapping.UserRoleMappingRepository;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -33,6 +35,9 @@ public class RoleServiceImpl implements RoleService { ...@@ -33,6 +35,9 @@ public class RoleServiceImpl implements RoleService {
@Autowired @Autowired
private PermissionRepository permissionRepository; private PermissionRepository permissionRepository;
@Autowired
private UserRoleMappingRepository userRoleMappingRepository;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result<Boolean> addRole(RoleModelVo roleModelVo) { public Result<Boolean> addRole(RoleModelVo roleModelVo) {
...@@ -144,6 +149,7 @@ public class RoleServiceImpl implements RoleService { ...@@ -144,6 +149,7 @@ public class RoleServiceImpl implements RoleService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Result<Boolean> deleteRole(Long roleId) { public Result<Boolean> deleteRole(Long roleId) {
final String LOG_PRE = "RoleServiceImpl.deleteRole"; final String LOG_PRE = "RoleServiceImpl.deleteRole";
userRoleMappingRepository.deleteAllByRoleId(roleId);
log.info("{} 删除角色 roleId={}", LOG_PRE, roleId); log.info("{} 删除角色 roleId={}", LOG_PRE, roleId);
if(roleId == null){ if(roleId == null){
log.error("{} 删除角色失败 id为空"); log.error("{} 删除角色失败 id为空");
...@@ -151,6 +157,7 @@ public class RoleServiceImpl implements RoleService { ...@@ -151,6 +157,7 @@ public class RoleServiceImpl implements RoleService {
} }
if (roleRepository.exists(roleId)) { if (roleRepository.exists(roleId)) {
roleRepository.delete(roleId); roleRepository.delete(roleId);
List<UserRoleMapping> allByRoleId = userRoleMappingRepository.findAllByRoleId(roleId);
} }
return Result.buildSuccess(true); return Result.buildSuccess(true);
......
package cn.quantgroup.cashloanflowboss.json; package cn.quantgroup.cashloanflowboss.json;
import cn.quantgroup.cashloanflowboss.spi.clf.model.LoanProgress;
import cn.quantgroup.cashloanflowboss.spi.clf.model.KANoticeType;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfOrderCallBack;
import cn.quantgroup.cashloanflowboss.spi.clf.model.CallbackRouter;
import java.sql.Timestamp;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfCallbackConfiguration;
import cn.quantgroup.cashloanflowboss.spi.clf.model.EncType;
import cn.quantgroup.cashloanflowboss.api.order.model.XyqbCurrentOrderStatusServiceResultModel; import cn.quantgroup.cashloanflowboss.api.order.model.XyqbCurrentOrderStatusServiceResultModel;
import cn.quantgroup.cashloanflowboss.api.permissionmodule.entity.Permission;
import cn.quantgroup.cashloanflowboss.core.base.ServiceResult; import cn.quantgroup.cashloanflowboss.core.base.ServiceResult;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfCallbackConfiguration;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfChannelConfiguration; import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfChannelConfiguration;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfOrderCallBack;
import cn.quantgroup.cashloanflowboss.spi.clf.model.CallbackRouter;
import cn.quantgroup.cashloanflowboss.spi.clf.model.EncType;
import cn.quantgroup.cashloanflowboss.spi.clf.model.KANoticeType;
import cn.quantgroup.cashloanflowboss.utils.JSONTools; import cn.quantgroup.cashloanflowboss.utils.JSONTools;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List; import java.sql.Timestamp;
/** /**
* @description: test * @description: test
...@@ -93,5 +88,4 @@ public class JsonTest { ...@@ -93,5 +88,4 @@ public class JsonTest {
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment