基本的组织管理完成
This commit is contained in:
parent
d9f54774bd
commit
187a5afbc2
@ -0,0 +1,46 @@
|
|||||||
|
package org.cmh.backend.OrganizationManagement.controller;
|
||||||
|
|
||||||
|
import org.cmh.backend.OrganizationManagement.model.Organization;
|
||||||
|
import org.cmh.backend.OrganizationManagement.service.OrganizationService;
|
||||||
|
import org.cmh.backend.authentication.model.User;
|
||||||
|
import org.cmh.backend.authentication.service.UserService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.springframework.http.ResponseEntity.ok;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/organizations")
|
||||||
|
public class OrganizationController {
|
||||||
|
@Autowired
|
||||||
|
private OrganizationService organizationService;
|
||||||
|
|
||||||
|
@GetMapping("/listAll")
|
||||||
|
public ResponseEntity<List<Organization>> listAll() {
|
||||||
|
List<Organization> data = organizationService.listAll();
|
||||||
|
System.out.println(data);
|
||||||
|
return ok(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/add")
|
||||||
|
public Organization add(@RequestBody Organization organization) {
|
||||||
|
return organizationService.add(organization);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/delete")
|
||||||
|
public String delete(@RequestBody Map<String, String> credentials) {
|
||||||
|
long id = Long.parseLong(credentials.get("id"));
|
||||||
|
organizationService.delete(id);
|
||||||
|
return "success";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/update")
|
||||||
|
public Organization update(@RequestBody Organization organization) {
|
||||||
|
return organizationService.update(organization);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,65 @@
|
|||||||
|
package org.cmh.backend.OrganizationManagement.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Table(name = "organizations")
|
||||||
|
@Entity
|
||||||
|
public class Organization {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
private long organizationId; // 部门ID,作为数据库表的主键
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "parent_organization_id")
|
||||||
|
private Organization parentOrganization; // 上级部门,如果有的话
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
private String organizationName; // 部门名称
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
private int displayOrder; // 显示排序
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
private String leader; // 负责人
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
private String contactPhone; // 联系电话
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
private String email; // 邮箱
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
private boolean organizationStatus;
|
||||||
|
|
||||||
|
public Organization() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Organization(Organization organization, String organizationName, int displayOrder, String leader, String contactPhone, String email, boolean organizationStatus) {
|
||||||
|
this.parentOrganization = organization;
|
||||||
|
this.organizationName = organizationName;
|
||||||
|
this.displayOrder = displayOrder;
|
||||||
|
this.leader = leader;
|
||||||
|
this.contactPhone = contactPhone;
|
||||||
|
this.email = email;
|
||||||
|
this.organizationStatus = organizationStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Organization{" +
|
||||||
|
"organizationId=" + organizationId +
|
||||||
|
", parentOrganization='" + parentOrganization + '\'' +
|
||||||
|
", organizationName='" + organizationName + '\'' +
|
||||||
|
", displayOrder=" + displayOrder +
|
||||||
|
", leader='" + leader + '\'' +
|
||||||
|
", contactPhone='" + contactPhone + '\'' +
|
||||||
|
", email='" + email + '\'' +
|
||||||
|
", organizationStatus='" + organizationStatus + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
package org.cmh.backend.OrganizationManagement.repository;
|
||||||
|
|
||||||
|
import org.aspectj.weaver.ast.Or;
|
||||||
|
import org.cmh.backend.OrganizationManagement.model.Organization;
|
||||||
|
import org.cmh.backend.OrganizationManagement.service.OrganizationService;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface OrganizationRepository extends JpaRepository<Organization, Long> {
|
||||||
|
|
||||||
|
List<Organization> findAll();
|
||||||
|
Organization save(Organization organization);
|
||||||
|
void deleteById(Long id);
|
||||||
|
Organization findByOrganizationId(Long id);
|
||||||
|
Organization findByOrganizationName(String name);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,36 @@
|
|||||||
|
package org.cmh.backend.OrganizationManagement.service;
|
||||||
|
|
||||||
|
import org.cmh.backend.OrganizationManagement.model.Organization;
|
||||||
|
import org.cmh.backend.OrganizationManagement.repository.OrganizationRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class OrganizationService {
|
||||||
|
@Autowired
|
||||||
|
private OrganizationRepository organizationRepository;
|
||||||
|
|
||||||
|
public List<Organization> listAll(){
|
||||||
|
return organizationRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Organization add(Organization organization){
|
||||||
|
return organizationRepository.save(organization);
|
||||||
|
}
|
||||||
|
public Organization update(Organization organization){
|
||||||
|
return organizationRepository.save(organization);
|
||||||
|
}
|
||||||
|
public String delete(Long id){
|
||||||
|
organizationRepository.deleteById(id);
|
||||||
|
return "success";
|
||||||
|
}
|
||||||
|
public Organization getById(Long organizationId){
|
||||||
|
return organizationRepository.findByOrganizationId(organizationId);
|
||||||
|
}
|
||||||
|
public Organization getByName(String name){
|
||||||
|
return organizationRepository.findByOrganizationName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -35,6 +35,7 @@ public class UserController {
|
|||||||
System.out.println("hahaha");
|
System.out.println("hahaha");
|
||||||
System.out.println("hahaha");
|
System.out.println("hahaha");
|
||||||
User user = userService.getUserByAccountAndPassword(account, password);
|
User user = userService.getUserByAccountAndPassword(account, password);
|
||||||
|
//判断逻辑
|
||||||
System.out.println(user);
|
System.out.println(user);
|
||||||
return ok(user);
|
return ok(user);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user