forked from RyanGoodwill/backend
Merge remote-tracking branch 'origin/personal/pjq/organization' into merge/1
# Conflicts: # src/main/java/org/cmh/backend/authentication/controller/AuthenticationController.java # src/main/java/org/cmh/backend/authentication/repository/UserRepository.java # src/main/java/org/cmh/backend/authentication/service/UserService.java
This commit is contained in:
commit
1a42273465
@ -0,0 +1,79 @@
|
|||||||
|
package org.cmh.backend.OrganizationManagement.controller;
|
||||||
|
|
||||||
|
import org.aspectj.weaver.ast.Or;
|
||||||
|
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.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
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("/addOrganization")
|
||||||
|
public Organization add(@RequestBody Map<String, String> credentials) {
|
||||||
|
Organization organization = new Organization();
|
||||||
|
if(credentials.get("organizationId") != null){
|
||||||
|
organization.setOrganizationId(Long.parseLong(credentials.get("organizationId")));
|
||||||
|
}
|
||||||
|
organization.setOrganizationName(credentials.get("organizationName"));
|
||||||
|
organization.setOrganizationStatus(Boolean.parseBoolean(credentials.get("organizationStatus")));
|
||||||
|
if(Integer.parseInt(credentials.get("parentOrganization")) != 0){
|
||||||
|
organization.setParentOrganization(organizationService.getById(Long.parseLong(credentials.get("parentOrganization"))));
|
||||||
|
}else{
|
||||||
|
organization.setParentOrganization(null);
|
||||||
|
}
|
||||||
|
organization.setEmail(credentials.get("email"));
|
||||||
|
organization.setLeader(credentials.get("leader"));
|
||||||
|
organization.setContactPhone(credentials.get("contactPhone"));
|
||||||
|
organization.setDisplayOrder(Integer.parseInt(credentials.get("displayOrder")));
|
||||||
|
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||||
|
String currentTime = sdf.format(new Date());
|
||||||
|
System.out.println(currentTime);
|
||||||
|
|
||||||
|
organization.setCreatedTime(currentTime);
|
||||||
|
Organization organizationAdd = organizationService.add(organization);
|
||||||
|
System.out.println(organizationAdd);
|
||||||
|
return organizationAdd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/deleteOrganization")
|
||||||
|
public String delete(@RequestBody Map<String, String> credentials) {
|
||||||
|
organizationService.delete(Long.valueOf(credentials.get("organizationId")));
|
||||||
|
return "success";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/update")
|
||||||
|
public Organization update(@RequestBody Organization organization) {
|
||||||
|
return organizationService.update(organization);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/getOrganizationById")
|
||||||
|
public Organization getById(@RequestBody Map<String, String> credentials) {
|
||||||
|
return organizationService.getById(Long.valueOf(credentials.get("organizationId")));
|
||||||
|
}
|
||||||
|
|
||||||
|
//ublic
|
||||||
|
}
|
||||||
@ -0,0 +1,70 @@
|
|||||||
|
package org.cmh.backend.OrganizationManagement.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Data;
|
||||||
|
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;
|
||||||
|
@Setter
|
||||||
|
@Getter
|
||||||
|
private String createdTime;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user