当前位置:网站首页>Platform management background and merchant menu resource management: Design of platform management background data service
Platform management background and merchant menu resource management: Design of platform management background data service
2022-06-26 16:58:00 【Seconds to write code】
Platform management background and business menu resource management
Platform management background is to provide services for operators of e-commerce platform , It mainly includes business management and some public configuration management functions . In the design of business management , Including business registration 、 to examine 、 Business user's authority management and menu resource management and other functions . In addition to the design of some public management functions , Platform management background itself also has the design of security control management .
The project engineering of platform management background is manage-microservice, Complete source code can be downloaded from the source code of this book .
The branch of the example code in this chapter is V2.1, Please pay attention to update . The development of platform management background mainly includes two parts , One part is the access control management design of the management background itself , The other part is the business and its menu resource management . The functions of these two parts are in the module manage-web To realize .

Platform management background data service design
Platform management background is an independent application system , It has its own user system and independent authority management design . The access control and authority management of the platform management background are mainly controlled by the operator 、 It's made up of roles and departments , What is the relationship between these entities : An operator can only be subordinate to one department , At the same time, an operator can have multiple roles .
Entity modeling
To achieve access control and simple rights management design , We define three entity objects , They are the operators 、 Roles and departments .
Operator's entity object Operators Mainly by name 、 mailbox 、 Gender 、 It is composed of password, department and other attributes , The implementation code is as follows :
@Entity
@Table (name = "toperator")
public class Operators extends IdEntity{
private String name;
private string email;private Integer sex;
@DateTimeFormat (pattern = "yyyy-MM-dd HH:mm :ss")
ecolumn(name = "created",columnDefinition = "timestamp defaultCurrent timestamp ")
@Temporal (TemporalType.TIMESTAMP)private Date created;
private String password;
@ManyToOne
@JoinColumn (name = "did")@JsonBackReference
private Department department;
@ManyToMany(cascade ={},fetch = FetchType.EAGER)@JoinTable(name = "operator part",
joinColumns = {@JoinColumn(name - "operator_id")},inverseJoinColumns = {@JoinColumn(name = "part_id")})
private List<Part> parts = new ArrayList<>();
public Operators() {
}
...
}In this design , It mainly realizes the operator's association relationship . On the one hand, it connects the Department entities in a many to one relationship , That is, an operator can only belong to one department ; On the other hand, role entities are associated with many to many relationships , That is, an operator can have multiple roles .
The entity object of the character Part It is mainly composed of attributes such as name and creation time , The implementation code is as follows :
@Entity
@Table(name = "t part")
public class Part extends IdEntity {
private String name;
@DateTimeFormat (pattern = "yyyy-MM-dd HH:mm:ss")
@Column (name = "created",columnDefinition = "timestamp defaultcurrenttimestamp")
@Temporal(TemporalType.TIMESTAMP)private Date created;
public Part(){
}
...
}This character design has no associated resources , Its access design will be implemented in a simpler way later in this chapter .
The entity object of the Department Department It is mainly composed of attributes such as name and creation time , The implementation code is as follows :
@Entity
@Table(name = "t department")
public class Department extends IdEntity {
private String name;
@DateTimeFormat (pattern = "yyyy-MM-dd HH:mm :ss")
eColumn (name = "created",columnDefinition = "timestamp defaultcurrent timestamp ")
@Temporal (TemporalType.TIMESTAMP)private Date created;
public Department (){
}
...
}In the design of association between entity objects , Using the design principle of one-way Association , That is, in the Department entity design , No longer associated with the operator . If you need to query the operator from the Department , You can use SQL Query statement implementation
In the entity object design above , All inherit an abstract class Baseld, It's used to implement ID Definition of primary key , The code is as follows :
@MappedSuperclass
public abstract class Baseld implements Serializable{
private static final long serialVersionUID =1L;
@Id
@Generatedvalue (strategy = GenerationType. IDENTITY)private Long id;
public Long getId() {
return id;
public void setId (Long id){
this.id= id;
}
}Give an action to an entity
Define a repository interface for the entity , By binding JPA The repository , You can give it some basic behavior , Realize the persistent design of entity . In the definition of the repository interface , You can also add other operation methods of an entity through declaration method .

For the operator entity object in the previous section , Its operation can be designed in the following ways :
@Repository
public interface OperatorRepository extends JpaRepository<Operators,Long>,JpaSpecificationExecutor<0perators> {
CQuery ("select t from Operators t where t.name =?1 and t.email =?2")Operators findByNameAndEmail(String name, String email);
GQuery ("select distinct u from Operators u where u.name= :name ")Operators findByName (RParam( "name") String name);
cQuery ("select distinct u from Operators u where u.id= :id")Operators findById(@Param("id") Long id);
@Query("select o from Operators o "+
"left join o.parts p"+
"where p.id= :id")
List<0perators> findByPartId(@Param ("id") Long id);
}Here are a few methods declared , It's all through SQL Query statements extend the behavior of operator entity objects . among findByPartld Realized through the Department ID Query operator list function .
in addition , In the persistence design of role entities and department entities , Just create a simple repository interface , By binding JPA Interface , The basic operation can be realized , I won't repeat .
Data access service design
Data access service is a service layer encapsulation design to call the repository interface , Through the development of service layer , It can provide unified transaction management for the call of repository interface , Implement other extension designs .
The development of operator entity data access service is taken as an example to illustrate .
For the general operation of adding, deleting, modifying and querying , You can use the design shown below :
@Service
@Transactional
public class OperatorService
CAutowired
private operatorRepository operatorRepository;
public String insert (Operators operators) {
try{
Operators old = findByName (operators .getName());
if(old == null) {
operatorRepository.save (operators) ;
return operators.getId() .toString();
}else{
return " user name '"+ old.getName()+” Already exist ! ";
}catch (Exception e) {
e.printStackTrace() ;
return e.getMessage() ;
}
}
public string update (Operators operators) {
try{
operatorRepository. save (operators) ;
return operators.getId() . toString() ;
}catch (Exception e){
e.printStackTrace() ;
return e.getMessage() ;
}}
public String delete (Long id) {
try{
operatorRepository .deleteById(id) ;
return id. toString() ;
}catch (Exception e) {
e.printStackTrace() ;
return e.getMessage() ;
}
}
public List<0perators>findA11(){
return operatorRepository.findAl1();
}
public Operators find0ne (Long id){
return operatorRepository.findByOperatorId(id);
}
public Operators findByName (string name){
return operatorRepository.findByName (name) ;
public List<Operators> findByPartId (Long partId){
return operatorRepository.findByPartId(partId);
}
}These methods all realize data access operation by calling the repository interface of operator entity . among , For the operator , Because you need to use a user name for login verification , Therefore, de duplication check is used when adding new data .

For paged queries , By defining a Specification Implement complex queries , The code is as follows :
@service
@Transactional
public class OperatorService {
@Autowired
private OperatorRepository operatorRepository;
public Page<0perators> findAll (0peratorsVo operatorsVo){
Sort sort = Sort.by (Sort.Direction.DESC, "created");
Pageable pageable = PageRequest.of(operatorsVo.getPage(),
operatorsVo.getsize(), sort);
return operatorRepository.findAll (new Specification<Operators>(){
@override
public Predicate toPredicate (Root<Operators> root, CriteriaQuery<
query, CriteriaBuilder criteriaBuilder) {
List<Predicate> predicatesList = new ArrayList<Predicate>();
if(CommonUtils.isNotNull (operatorsVo.getName())){
predicatesList.add (criteriaBuilder.like (root.get ("name"),
"g"+operatorsVo.getName() +"o"));
}
if (CommonUtils.isNotNull(operatorsVo.getCreated())){
predicatesList.add (criteriaBuilder.greaterhan (root.get ("created"),operatorsVo. getCreated()));
query.where(predicatesList.toArray (new
Predicate[predicatesList.size()]));
return query.getRestriction();
},pageable);
}
}among , The parameters of paging query can be designed as needed , Only operator name and creation date are provided for query .
among , The parameters of paging query can be designed as needed , Only operator name and creation date are provided for query .
unit testing
After completing the design of data access service , You can do a unit test , To verify that the design is correct .
Here's a test case for inserting data , Through this test case, we can create an administrator user who logs in to the system :
@Runwith (SpringRunner.class)
@ContextConfiguration (classes ={JpaConfiguration.class,ManageRestApiApplication.class})
@SpringBootTest
public class BbServiceTest {
private static Logger logger =
LoggerFactory.getLogger (BbServiceTest.class);
@Autowired
private OperatorService operatorService;@Autowired
private PartService partService;@Autowired
private DepartmentService departmentService;
@Test
public void insertData(){
Partpart=new Part(;part.setName ( "admins");
partService.save(part);
Department department = new Department ();department.setName(" Technology Department ");
departmentService.save(department);
Operators operators =new Operators();operators.setName ("admin");
operators.setSex(1);
operators.set Department (department);
List<Part> partList = operators.getParts();partList.add(part);
operators.setParts(partList);
BCryptPasswordEncoder bc = new BCryptPasswordEncoder();operators.setPassword(bc.encode ( "123456"));
operatorService.insert(operators);
assert operators.getId() >0: "create error";
}
}This test case does the following :
(1) Created a character , The name is admins( You can also think of it as a user group ).
(2) Created a department , It's called technology department .
(3) A user is created , The name is admin, And set the password to 123456.
If the test is successful , Then the generated data can be used for later development . We can use admin This user logs in as a system administrator .
Other test cases can be designed according to this method .
The content of this article is platform management background and business menu resource management : Platform management background data service design
- The next article is to explain the platform management background and business menu resource management : Platform management background access control design ;
- Friends who think the article is good can forward this article and pay attention to Xiaobian ;
- Thank you for your support !
边栏推荐
- 防火 疏散 自救…这场安全生产暨消防培训干货满满!
- Redis overview
- Redis OM . Net redis object mapping framework
- [suggested collection] 11 online communities suitable for programmers
- COMP5216 Mobile Computing Assignment 1 - Extending ToDoList app
- Interpretation of new plug-ins | how to enhance authentication capability with forward auth
- Use the array to calculate the average of N numbers, and output the numbers greater than the average
- Record the use process of fenics
- Discussion: the next generation of stable coins
- Multiply the values of the upper triangular elements of the array by M
猜你喜欢
![[Li Kou brush questions] 11 Container holding the most water //42 Rain water connection](/img/45/1e712300ea655856762394fba09066.png)
[Li Kou brush questions] 11 Container holding the most water //42 Rain water connection

数字藏品与NFT到底有何区别

Cloud platform monitoring system based on stm32+ Huawei cloud IOT design
![[force deduction question] two point search: 4 Find the median of two positive arrays](/img/4f/43aa7e14344e7e1a2fb7c1d209d13b.png)
[force deduction question] two point search: 4 Find the median of two positive arrays

Teach you to learn dapr - 4 Service invocation

I regard it as a dry product with a monthly income of more than 30000 yuan for sidelines and more than 10000 yuan for novices!

Summary of all knowledge points of C language

What does the inner structure of the neural network "alchemy furnace" look like? An interpretation of the thesis by the doctor of Oxford University
![[from database deletion to running] JDBC conclusion (finish the series in one day!! run as soon as you finish learning!)](/img/75/2fb1a4e6215e404df34849e9e4f21a.png)
[from database deletion to running] JDBC conclusion (finish the series in one day!! run as soon as you finish learning!)

Make up the weakness - Open Source im project openim about initialization / login / friend interface document introduction
随机推荐
The texstudio official website cannot be opened
构造函数和析构函数
[force deduction question] two point search: 4 Find the median of two positive arrays
Redis migration (recommended operation process)
5g is not flat and 6G is restarted. China leads wireless communication. What is the biggest advantage of 6G?
LeetCode Algorithm 24. 两两交换链表中的节点
Turtle cartography
Summary of all knowledge points of C language
Programmer's essential toolkit, please collect!
Interpretation of cloud native microservice technology trend
day10每日3题(2):统计最大组的数目
Stm32h7b0 replaces the h750 program, causing the MCU to hang up and unable to burn the program
Memory partition model
Cloud platform monitoring system based on stm32+ Huawei cloud IOT design
Day10 daily 3 questions (3): String Matching in array
【MATLAB项目实战】基于卷积神经网络与双向长短时(CNN-LSTM)融合的锂离子电池剩余使用寿命预测
Byte interview: two array interview questions, please accept
Teach you to learn dapr - 3 Run the first with dapr Net program
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
The student record consists of student number and academic performance. The data of n students have been stored in the a structure array to find out the student record with the lowest performance