0% found this document useful (0 votes)
3 views12 pages

Warehouse New

Uploaded by

akhyad54321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views12 pages

Warehouse New

Uploaded by

akhyad54321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

package sa.tabadul.pcs.warehouse.api.v1.

controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import sa.tabadul.pcs.warehouse.actuate.common.ApiResponse;
import sa.tabadul.pcs.warehouse.api.v1.request.ApproveRejectRequest;
import sa.tabadul.pcs.warehouse.api.v1.request.PaginationRequestModel;
import sa.tabadul.pcs.warehouse.api.v1.response.PaginationResponseModel;
import sa.tabadul.pcs.warehouse.dto.CargoStorageRequestDto;
import sa.tabadul.pcs.warehouse.service.CargoStorageService;

@RestController
@RequestMapping("/cargostorage")
@Slf4j
@CrossOrigin(origins = "*", allowedHeaders = "*")
public class CargoStorageController {

@Autowired
private CargoStorageService cargoStorageService;

@PostMapping("/add-update")
public ResponseEntity<ApiResponse<?>>
addUpdateCargoStorageRequest(@RequestBody CargoStorageRequestDto
cargoStorageRequestDto) {
log.info("CargoStorageController - Inside addUpdateCargoStorageRequest
method");
return
cargoStorageService.addUpdateCargoStorageRequest(cargoStorageRequestDto);
}

@GetMapping("/view")
public ResponseEntity<ApiResponse<?>>
viewCargoStorageRequest(@RequestParam(name = "crn") Long crn) {
log.info("CargoStorageController - Inside viewCargoStorageRequest
method");
return cargoStorageService.viewCargoStorageRequest(crn);
}

@PostMapping("/cargo-storage-listing")
public PaginationResponseModel paginationRequest(@RequestBody
PaginationRequestModel p) {
log.info("CargoStorageController - Inside paginationRequest method");
return cargoStorageService.getCargoStorageList(p);
}

@PostMapping("/approve-reject")
public ResponseEntity<ApiResponse<?>>
approveRejectRequest(@RequestBody ApproveRejectRequest
approveRejectRequest) {
log.info("CargoStorageController - Inside approveRejectRequest method");
return cargoStorageService.approveRejectRequest(approveRejectRequest);
}
}

package sa.tabadul.pcs.warehouse.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import sa.tabadul.pcs.warehouse.actuate.common.ApiResponse;
import sa.tabadul.pcs.warehouse.actuate.common.CodeMaster;
import sa.tabadul.pcs.warehouse.actuate.common.ConstantValues;
import sa.tabadul.pcs.warehouse.api.v1.request.ApproveRejectRequest;
import sa.tabadul.pcs.warehouse.api.v1.request.Key;
import sa.tabadul.pcs.warehouse.api.v1.request.PaginationRequestModel;
import sa.tabadul.pcs.warehouse.api.v1.response.PaginationResponseModel;
import sa.tabadul.pcs.warehouse.domain.CargoStorageRequestApprovalEntity;
import sa.tabadul.pcs.warehouse.domain.CargoStorageRequestEntity;
import sa.tabadul.pcs.warehouse.domain.enums.CommonCodes;
import sa.tabadul.pcs.warehouse.domain.enums.ExceptionCodes;
import sa.tabadul.pcs.warehouse.domain.enums.SearchCommonStatus;
import sa.tabadul.pcs.warehouse.domain.enums.SuccessCodes;
import sa.tabadul.pcs.warehouse.dto.CargoStorageRequestDto;
import sa.tabadul.pcs.warehouse.exception.DataNotFoundException;
import sa.tabadul.pcs.warehouse.remote.RestService;
import sa.tabadul.pcs.warehouse.repository.ApproveRejectRepository;
import sa.tabadul.pcs.warehouse.repository.CargoStorageRepository;
import
sa.tabadul.pcs.warehouse.repository.specifications.CargoStorageRequestSpecific
ation;
import sa.tabadul.pcs.warehouse.util.Utils;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.*;

import static sa.tabadul.pcs.warehouse.actuate.common.ConstantValues.FOUR;


import static sa.tabadul.pcs.warehouse.actuate.common.ConstantValues.ONE;

@Service
@Slf4j
public class CargoStorageService {

@Autowired
private CargoStorageRepository cargoStorageRepository;

@Autowired
private ApproveRejectRepository approveRejectRepository;

@Autowired
private Utils utils;

@Autowired
private ObjectMapper objectMapper;

@Autowired
CommonHttpUrlConnections httpConnections;

@Autowired
private RestService restService;

public ResponseEntity<ApiResponse<?>>
addUpdateCargoStorageRequest(CargoStorageRequestDto
cargoStorageRequestDto) {
log.info("CargoStorageService - Inside addUpdateCargoStorageRequest
method");
CargoStorageRequestEntity cargoStorageRequestEntity =
objectMapper.convertValue(cargoStorageRequestDto,
CargoStorageRequestEntity.class);
Map<String, Object> result = new HashMap<>();
try {
long generatedCRN = utils.generateCRN();
cargoStorageRequestEntity.setCrn(generatedCRN);
cargoStorageRequestEntity.setCreatedDate(LocalDateTime.now());
CargoStorageRequestEntity savedCargoStorageRequest =
cargoStorageRepository.save(cargoStorageRequestEntity);

if (cargoStorageRequestEntity.getLoadType().equals(ONE)) {
result.put("Generated CRN: ", savedCargoStorageRequest.getCrn());
ApiResponse<Map<String, Object>> apiResponse = new
ApiResponse<>(HttpStatus.OK.value(),
SuccessCodes.SUCCESSFULL_SSR_INSERT_CARGO.getMessage(),
result);
return ResponseEntity.ok(apiResponse);
} else {
result.put("Generated CRN: ", savedCargoStorageRequest.getCrn());
ApiResponse<Map<String, Object>> apiResponse = new
ApiResponse<>(HttpStatus.OK.value(),

SuccessCodes.SUCCESSFULL_SSR_INSERT_CONTAINER.getMessage(), result);
return ResponseEntity.ok(apiResponse);
}
} catch (HttpServerErrorException | HttpClientErrorException e) {
ApiResponse<String> apiResponse = new ApiResponse<>(
HttpStatus.INTERNAL_SERVER_ERROR.value(),
ExceptionCodes.INSERT_FAILED.getMessage() + e.getMessage());
log.error(ConstantValues.ERROR_MESSAGE, e.getMessage(), e);
return
ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(apiResponse)
;
}
}

public ResponseEntity<ApiResponse<?>> viewCargoStorageRequest(Long


crn) {
log.info("CargoStorageService - Inside viewCargoStorageRequest method");
Optional<CargoStorageRequestEntity> optionalCargoStorageEntity =
cargoStorageRepository.findByCrn(crn);
if (optionalCargoStorageEntity.isEmpty()) {
throw new DataNotFoundException(ExceptionCodes.DATA_NOT_FOUND);
}
ApiResponse<CargoStorageRequestEntity> apiResponse = new
ApiResponse<>(HttpStatus.OK.value(),

SuccessCodes.SUCCESSFULL_CARGO_STORAGE_REQUEST_INSERT.getMessage(),
optionalCargoStorageEntity.get());
return ResponseEntity.ok(apiResponse);
}

// --------------------------------------Pagination
api-------------------------------------------------
public PaginationResponseModel
getCargoStorageList(PaginationRequestModel pagination) {
Key keys = pagination.getKeys();
PageRequest pageable = utils.createPageable(pagination);
List<CargoStorageRequestEntity> results;
long keysFilteredCount = 0;
Integer filterStatus = null;
if (keys != null) {
List<Integer> getCargoTypeMaster = null;
if (pagination.getFilter() != null) {
// filterLoadType =
getLoadTypeMaster(pagination.getFilter().getLoadType());
filterStatus =
SearchCommonStatus.getStatusCodes(pagination.getFilter().getApprovalStatus()
);
} else if (pagination.getSearch() != null) {
getCargoTypeMaster = getCargoTypeMaster(pagination.getSearch());
}

Specification<CargoStorageRequestEntity> spec = new


CargoStorageRequestSpecification(pagination, getCargoTypeMaster,
filterStatus);
results = cargoStorageRepository.findAll(spec, pageable).getContent();
keysFilteredCount = cargoStorageRepository.count(spec);
if (!results.isEmpty()) {
List<Map<String, Object>> listMap =
cargoStorageRequestPaginationResponse(results);
return new PaginationResponseModel(cargoStorageRepository.count(),
keysFilteredCount, listMap);
}
}
return new PaginationResponseModel(cargoStorageRepository.count(),
keysFilteredCount,
Collections.emptyList());
}

private List<Integer> getCargoTypeMaster(String cargoType) {


Map<String, List<String>> requestBody = new HashMap<>();
List<String> list = new ArrayList<>();
list.add("CARGO_TYPES");
requestBody.put("key1", list);
List<CodeMaster> codeMastersList;
codeMastersList = httpConnections.getCodeMasterList(requestBody);
List<Integer> result = new ArrayList<>();
for (CodeMaster master : codeMastersList) {
String description = master.getCodeDescriptionEnglish();
if (isEqualIgnoreCase(description, cargoType)) {
result.add(master.getId());
}
}
return result;
}

private boolean isEqualIgnoreCase(String str1, String str2) {


return str1 != null && str2 != null && str1.equalsIgnoreCase(str2);
}

private List<Map<String, Object>>


cargoStorageRequestPaginationResponse(List<CargoStorageRequestEntity>
results) {
// List<Integer> voyageIdList =
results.stream().map(cargoStorageRequestEntity ->
cargoStorageRequestEntity.getVoyageID()).collect(Collectors.toList());
// System.out.println("voyageIdList : " + voyageIdList);
// Map<String, List<Integer>> response = new HashMap<>();
// response.put("voyageID", voyageIdList);
// Object object = httpConnections.getVesselVoyageDetails(response);
// System.out.println("Object = " + object);
//
-----------------------------------------------------------------------------------------------------------------
--------
List<Map<String, Object>> listMap = new ArrayList<>();
for (CargoStorageRequestEntity cargoStorageRequest : results) {
Map<String, Object> responseMap = new HashMap<>();
responseMap.put("id", cargoStorageRequest.getId());
responseMap.put("crn", cargoStorageRequest.getCrn());
responseMap.put("requestDate",
cargoStorageRequest.getCreatedDate());
responseMap.put("cargoWeight",
cargoStorageRequest.getCargoWeight());
responseMap.put("status", cargoStorageRequest.getApprovalStatus());
listMap.add(responseMap);
}
return listMap;
}

public ResponseEntity<ApiResponse<?>>
approveRejectRequest(ApproveRejectRequest approveRejectRequest) {
log.info("CargoStorageService - Inside approveRejectRequest method");
Optional<CargoStorageRequestEntity> optionalCargoStorageRequestEntity
= cargoStorageRepository.findById(approveRejectRequest.getId());
if (optionalCargoStorageRequestEntity.isEmpty()) {
throw new DataNotFoundException(ExceptionCodes.DATA_NOT_FOUND);
}
CargoStorageRequestEntity cargoStorageRequest =
optionalCargoStorageRequestEntity.get();

cargoStorageRequest.setApprovalStatus(approveRejectRequest.getApprovalStat
us());

cargoStorageRequest.setUpdatedBy(approveRejectRequest.getUpdatedBy());
cargoStorageRequest.setUpdatedDate(LocalDateTime.now());
cargoStorageRepository.save(cargoStorageRequest);

CargoStorageRequestApprovalEntity child = new


CargoStorageRequestApprovalEntity();
child.setApprovalStatus(approveRejectRequest.getApprovalStatus());
child.setCreatedBy(approveRejectRequest.getUpdatedBy());
child.setCreatedDate(LocalDateTime.now());
child.setUpdatedBy(approveRejectRequest.getUpdatedBy());
child.setUpdatedDate(LocalDateTime.now());
child.setUser(approveRejectRequest.getUser());
child.setRemarks(approveRejectRequest.getRemark());
child.setCsrNo(utils.generateCSRNO());
CargoStorageRequestEntity existing = new CargoStorageRequestEntity();
existing.setId(approveRejectRequest.getId());
child.setCargoStorageRequestApproval(existing);
approveRejectRepository.save(child);

if (approveRejectRequest.getApprovalStatus().equals(FOUR)) {
Map<String, Object> result = new HashMap<>();
result.put(CommonCodes.CRN.getMessage(),
cargoStorageRequest.getCrn());
ApiResponse<Map<String, Object>> apiResponse = new
ApiResponse<>(HttpStatus.OK.value(),
SuccessCodes.SUCCESSFULL_REJECTED.getMessage(), result);
return ResponseEntity.ok(apiResponse);
}
Map<String, Object> result = new HashMap<>();
result.put(CommonCodes.CRN.getMessage(),
cargoStorageRequest.getCrn());
ApiResponse<Map<String, Object>> apiResponse = new
ApiResponse<>(HttpStatus.OK.value(),
SuccessCodes.SUCCESSFULL_CANCELLED.getMessage(), result);
return ResponseEntity.ok(apiResponse);
}

package sa.tabadul.pcs.warehouse.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import sa.tabadul.pcs.warehouse.actuate.common.ConstantValues;
import sa.tabadul.pcs.warehouse.domain.CargoStorageRequestApprovalEntity;
import sa.tabadul.pcs.warehouse.domain.CargoStorageRequestCargoEntity;
import sa.tabadul.pcs.warehouse.domain.CargoStorageRequestContainerEntity;

import javax.persistence.Column;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class CargoStorageRequestDto {
private int id;

private int spaceBookingID;

private Long crn;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern =


ConstantValues.YYYY_MM_DD_HH_MM)
private LocalDateTime dischargeLoadDate;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern =


ConstantValues.YYYY_MM_DD_HH_MM)
private LocalDateTime fromDate;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern =


ConstantValues.YYYY_MM_DD_HH_MM)
private LocalDateTime toDate;

private Long cargoType;

private Double cargoWeight;

private Double totalVolume;

private Long approvalStatus;

private Integer manifestType;

private int manifestNo;

private LocalDate manifestDate;

private int manifestDoc;

private int deliverOrderDoc;

private int blCopyDoc;

private int otherDoc;

private Integer loadType;

private String orgID;

private String branchID;

private Integer portID;

private List<CargoStorageRequestApprovalEntity> approval = new


ArrayList<>();

private List<CargoStorageRequestCargoEntity> cargo = new ArrayList<>();

private List<CargoStorageRequestContainerEntity> container = new


ArrayList<>();

private String createdBy;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern =


ConstantValues.YYYY_MM_DD_HH_MM)
private LocalDateTime createdDate;

private String updatedBy;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern =


ConstantValues.YYYY_MM_DD_HH_MM)
private LocalDateTime updatedDate;

private boolean isActive;


}

package sa.tabadul.pcs.warehouse.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import
sa.tabadul.pcs.warehouse.actuate.common.CommonEntityLocalDateTime;
import sa.tabadul.pcs.warehouse.actuate.common.ConstantValues;

import javax.persistence.*;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "CARGO_STORAGE_REQUEST", schema = "STORAGE")
public class CargoStorageRequestEntity extends CommonEntityLocalDateTime {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

@Column(name = "space_booking_id")
private int spaceBookingID;

@Column(name = "CRN")
private Long crn;

@Column(name = "discharge_load_date")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern =
ConstantValues.YYYY_MM_DD_HH_MM)
private LocalDateTime dischargeLoadDate;

@Column(name = "from_date")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern =
ConstantValues.YYYY_MM_DD_HH_MM)
private LocalDateTime fromDate;

@Column(name = "to_date")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern =
ConstantValues.YYYY_MM_DD_HH_MM)
private LocalDateTime toDate;

@Column(name = "cargo_type_RID")
private Long cargoType;

@Column(name = "cargo_weight")
private Double cargoWeight;

@Column(name = "total_volume")
private Double totalVolume;

@Column(name = "approval_status_RID")
private Long approvalStatus;

@Column(name = "manifest_type_RID")
private Integer manifestType;

@Column(name = "manifest_no")
private int manifestNo;

@Column(name = "manifest_date")
private LocalDate manifestDate;

@Column(name = "manifest_doc")
private int manifestDoc;

@Column(name = "deliver_order_doc")
private int deliverOrderDoc;
@Column(name = "bl_copy_doc")
private int blCopyDoc;

@Column(name = "other_doc")
private int otherDoc;

@Column(name = "load_type_RID")
private Integer loadType;

@Column(name = "org_RID")
private String orgID;

@Column(name = "branch_RID")
private String branchID;

@Column(name = "port_RID")
private Integer portID;

@OneToMany(mappedBy = "cargoStorageRequestApproval", cascade =


CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
@JsonManagedReference
private List<CargoStorageRequestApprovalEntity> approval = new
ArrayList<>();

@OneToMany(mappedBy = "cargoStorageRequestCargo", cascade =


CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
@JsonManagedReference
private List<CargoStorageRequestCargoEntity> cargo = new ArrayList<>();

@OneToMany(mappedBy = "cargoStorageRequestContainer", cascade =


CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
@JsonManagedReference
private List<CargoStorageRequestContainerEntity> container = new
ArrayList<>();

}
-----------------------------------------------------------------------------------------------------------------
------------package sa.tabadul.pcs.warehouse.actuate.common;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import sa.tabadul.pcs.warehouse.service.ValidationGroup;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.validation.constraints.Size;
import java.time.LocalDate;
import java.time.LocalDateTime;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@MappedSuperclass
public class CommonEntityLocalDateTime {

@Column(name = "created_by")
@Size(max = 72, message = ConstantValues.CREATED_BY, groups =
ValidationGroup.class)
private String createdBy;

@Column(name = "created_date")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern =
ConstantValues.YYYY_MM_DD_HH_MM)
private LocalDateTime createdDate;

@Column(name = "updated_by")
@Size(max = 72, message = ConstantValues.UPDATED_BY, groups =
ValidationGroup.class)
private String updatedBy;

@Column(name = "updated_date")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern =
ConstantValues.YYYY_MM_DD_HH_MM)
private LocalDateTime updatedDate;

@Column(name = "is_active")
private boolean isActive;

@PrePersist
private void prePersist() {
createdDate = LocalDateTime.now();
isActive=true;
}
@PreUpdate
public void preUpdate() {
updatedDate = LocalDateTime.now();
}

You might also like