Compare commits
No commits in common. "54f055dea981ca4a82614eb3ee5c2f36b418ca19" and "441c9841082fbe10cf851d4592e5db1f560f3b6d" have entirely different histories.
54f055dea9
...
441c984108
@ -1,79 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
||||||
@ -1,70 +0,0 @@
|
|||||||
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 + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,36 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package org.cmh.backend.authentication.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
class AuthenticationController {
|
||||||
|
@GetMapping("/hello")
|
||||||
|
public String hello(){
|
||||||
|
return "Hello SpringBoot!";
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/main/java/org/cmh/backend/authentication/model/User.java
Normal file
39
src/main/java/org/cmh/backend/authentication/model/User.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package org.cmh.backend.authentication.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class User {
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
private String username;
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
package org.cmh.backend.authentication.repository;
|
||||||
|
|
||||||
|
import org.cmh.backend.authentication.model.User;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface UserRepository extends JpaRepository<User, Long> {
|
||||||
|
User findByUsername(String username);
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package org.cmh.backend.authentication.service;
|
||||||
|
|
||||||
|
import org.cmh.backend.authentication.model.User;
|
||||||
|
import org.cmh.backend.authentication.repository.UserRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UserService {
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
public User getUserByUsername(String username) {
|
||||||
|
return userRepository.findByUsername(username);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user