personal/pjq/organization #3
@ -1,5 +1,6 @@
|
||||
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;
|
||||
@ -8,7 +9,9 @@ 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;
|
||||
|
||||
@ -23,19 +26,42 @@ public class OrganizationController {
|
||||
@GetMapping("/listAll")
|
||||
public ResponseEntity<List<Organization>> listAll() {
|
||||
List<Organization> data = organizationService.listAll();
|
||||
System.out.println(data);
|
||||
// System.out.println(data);
|
||||
return ok(data);
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
public Organization add(@RequestBody Organization organization) {
|
||||
return organizationService.add(organization);
|
||||
@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("/delete")
|
||||
|
||||
@PostMapping("/deleteOrganization")
|
||||
public String delete(@RequestBody Map<String, String> credentials) {
|
||||
long id = Long.parseLong(credentials.get("id"));
|
||||
organizationService.delete(id);
|
||||
organizationService.delete(Long.valueOf(credentials.get("organizationId")));
|
||||
return "success";
|
||||
}
|
||||
|
||||
@ -43,4 +69,9 @@ public class OrganizationController {
|
||||
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")));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
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 {
|
||||
@ -35,6 +37,9 @@ public class Organization {
|
||||
@Setter
|
||||
@Getter
|
||||
private boolean organizationStatus;
|
||||
@Setter
|
||||
@Getter
|
||||
private String createdTime;
|
||||
|
||||
public Organization() {
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user