Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import com.innovature.Library.entity.Borrow;
import com.innovature.Library.form.BorrowForm;
import com.innovature.Library.service.BorrowService;
import com.innovature.Library.service.impl.BorrowServiceImpl;
import com.innovature.Library.view.BorrowDetailView;
import com.innovature.Library.view.rentChartView;
//import com.innovature.Library.view.BorrowListView;
import com.innovature.Library.view.BorrowListView;

Expand All @@ -39,6 +41,9 @@ public class BorrowController {
@Autowired
private BorrowService bService;

@Autowired
private BorrowServiceImpl borrowServices;


//load all borrow list
@GetMapping
Expand Down Expand Up @@ -254,6 +259,16 @@ public BorrowDetailView undo(



/////////////////////////////////////



@GetMapping("/admin/chart")
public rentChartView getchart(){
rentChartView test =borrowServices.getChart();
return test;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -61,28 +61,5 @@ public ResponseEntity<ResponseMessage> uploadFile(@RequestParam("file") Multipar
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseMessage(message,""));
}

@GetMapping("/tutorials")
public ResponseEntity<List<csvUpload>> getAllTutorials() {
try {
List<csvUpload> tutorials = csvService.getAll();

if (tutorials.isEmpty()) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

return new ResponseEntity<>(tutorials, HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}

@GetMapping("/download")
public ResponseEntity<Resource> downloadFile() {
InputStreamResource file = new InputStreamResource(csvService.load());

return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;")
.contentType(MediaType.parseMediaType("application/csv"))
.body(file);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,7 @@ public static boolean hasCSVFormat(MultipartFile file){

}

public static ByteArrayInputStream loadFromdb(List<csvUpload>csvList){
final CSVFormat format=CSVFormat.DEFAULT.withQuoteMode(QuoteMode.MINIMAL);
try(ByteArrayOutputStream out=new ByteArrayOutputStream();
CSVPrinter csvPrinter=new CSVPrinter(new PrintWriter(out),format);){
String[] HEADERs={"books_name","books_auther","publication","books_copies","category_id","status"};
csvPrinter.printRecord(HEADERs);
for( csvUpload csv:csvList){
List<String>data=Arrays.asList(
//String.valueOf(csv.getBooksId()),
csv.getBooksName(),
csv.getBooksAuther(),
csv.getPublication(),
String.valueOf(csv.getBooksCopies()),
String.valueOf(csv.getCategoryId()),
String.valueOf(csv.getStatus())
// csv.getImage()
);
csvPrinter.printRecord(data);

}
csvPrinter.flush();
return new ByteArrayInputStream(out.toByteArray());
}catch(IOException e){
throw new RuntimeException("fail to import data to CSV file: " + e.getMessage());
}
}
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.innovature.Library.entity;

import java.time.LocalDateTime;
import java.util.Date;
//import java.util.Objects;

Expand Down Expand Up @@ -31,15 +32,17 @@ private Status(byte value) {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer borrowId;

@Temporal(TemporalType.DATE)
private Date issueDate;
// @Temporal(TemporalType.DATE)
private LocalDateTime issueDate;

@Temporal(TemporalType.DATE)
private Date returnDate;

@Temporal(TemporalType.DATE)
private Date dueDate;

@Temporal(TemporalType.DATE)
private Date bookReturnedDate;
//@Temporal(TemporalType.DATE)
private LocalDateTime bookReturnedDate;

@ManyToOne(optional = false, fetch = FetchType.EAGER)
private Books books;
Expand All @@ -66,23 +69,17 @@ public Borrow(Integer borrowId) {

public Borrow(BorrowForm form, Books books, User user2) {

// Date dt = new Date();
// this.issueDate= dt;
// this.user = new User(user2);
// this.booksId=form.getBooksId();

// this.issueDate = form.getIssueDate();
this.returnDate = form.getReturnDate();
this.dueDate = form.getDueDate();
this.books = books;
this.user = user2;
this.status = getStatus();
this.reason = form.getReason();

Date dt = new Date();
LocalDateTime dt =LocalDateTime.now();
this.issueDate = dt;

Date date = new Date();
LocalDateTime date =LocalDateTime.now();
this.bookReturnedDate = date;
this.dueDays=0L;
this.fine=0L;
Expand All @@ -105,11 +102,11 @@ public void setBorrowId(Integer borrowId) {
this.borrowId = borrowId;
}

public Date getIssueDate() {
public LocalDateTime getIssueDate() {
return issueDate;
}

public void setIssueDate(Date issueDate) {
public void setIssueDate(LocalDateTime issueDate) {
this.issueDate = issueDate;
}

Expand Down Expand Up @@ -161,11 +158,11 @@ public void setReason(String reason) {
this.reason = reason;
}

public Date getBookReturnedDate() {
public LocalDateTime getBookReturnedDate() {
return bookReturnedDate;
}

public void setBookReturnedDate(Date bookReturnedDate) {
public void setBookReturnedDate(LocalDateTime bookReturnedDate) {
this.bookReturnedDate = bookReturnedDate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,11 @@ public interface BorrowRepository extends PagingAndSortingRepository<Borrow, Int
Integer findbyUserIdAndStatus(Integer userId);


@Query(value = "SELECT * FROM borrow",nativeQuery = true)
List<Borrow>findAllC();


}

//mysql> select count(borrow_id) from borrow where book_returned_date between '2023-01-01' and '2023-01-07';
//select count(borrow_id) from borrow where book_returned_date='2022-12-27';
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ public interface BorrowService {

Integer BorrowBlock();

// public RentCharView getChart();


}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ public void save(MultipartFile file){
}
}

public ByteArrayInputStream load(){
List<csvUpload> csvTest=repository.findAll();
ByteArrayInputStream in=csvHelper.loadFromdb(csvTest);
return in;
}


public List<csvUpload>getAll(){
return repository.findAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
import java.util.Date;
//import java.sql.Date;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;



import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -30,6 +42,8 @@

import com.innovature.Library.view.BorrowDetailView;
import com.innovature.Library.view.BorrowListView;
import com.innovature.Library.view.rentChartView;

import java.util.List;


Expand Down Expand Up @@ -150,7 +164,7 @@ public BorrowDetailView updates(Integer borrowId, BorrowForm form) {
Books books=booksRepository.findbyBorrowId(borrowId);


borrow.setIssueDate(new Date());
borrow.setIssueDate(LocalDateTime.now());
borrow.setDueDate(form.getDueDate());
borrow.setReturnDate(form.getReturnDate());
borrow.setReason(null);
Expand Down Expand Up @@ -191,7 +205,7 @@ public BorrowDetailView updateReturn(Integer borrowId, BorrowForm form) {
Books books=booksRepository.findbyBorrowId(borrowId);


borrow.setBookReturnedDate(new Date());
borrow.setBookReturnedDate(LocalDateTime.now());
borrow.setIssueDate(borrow.getIssueDate());
borrow.setReturnDate(borrow.getReturnDate());
borrow.setDueDate(borrow.getDueDate());
Expand Down Expand Up @@ -418,6 +432,92 @@ public void fineGeneration() {

}


public rentChartView getChart(){
rentChartView result= new rentChartView();
String[] weeks = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
result.setLabel(Arrays.asList(weeks));

HashMap<Integer, Result> hm
= new HashMap<Integer, Result>();

hm.put(1, new Result(0, 0));
hm.put(2, new Result(0, 0));
hm.put(3, new Result(0, 0));
hm.put(4, new Result(0, 0));
hm.put(5, new Result(0, 0));
hm.put(6, new Result(0, 0));
hm.put(7, new Result(0, 0));

List<Borrow>s=borrowRepository.findAllC();


for(Borrow a:s){
if(a.getStatus().equals("APPROVED"))
{

LocalDateTime b = a.getIssueDate();
System.out.println("---------------------------"+b);
// System.out.println("........>>>>>>>>>>>>>>>>....."+ b.getDayOfWeek().getValue());

hm.put(b.getDayOfWeek().getValue(), new Result(hm.get(b.getDayOfWeek().getValue()).getIssueCount() + 1,
hm.get(b.getDayOfWeek().getValue()).getReturnedCount()));
}
LocalDateTime c=null;

if(a.getStatus().equals("RETURNED"))
{

c = a.getBookReturnedDate();
System.out.println("cccccccccccccccccccccccccccccccccccccccccc="+c);


hm.put(c.getDayOfWeek().getValue(), new Result(hm.get(c.getDayOfWeek().getValue()).getIssueCount() ,
hm.get(c.getDayOfWeek().getValue()).getReturnedCount() +1));

System.out.println(hm.get(c.getDayOfWeek().getValue()).getReturnedCount());
}

// System.out.println(b.getDayOfWeek().getValue());
// System.out.println(hm.get(b.getMonth().getValue()).getReturnCount());


}
for (Map.Entry<Integer, Result > mapElement : hm.entrySet()) {
result.getIssueCount().add(mapElement.getValue().getIssueCount()+"");
result.getReturnedCount().add(mapElement.getValue().getReturnedCount()+"");

}
return result;
}


public class Result {
private Integer issueCount;
private Integer returnedCount;

public Result(Integer issueCount, Integer returnedCount) {
this.issueCount = issueCount;
this.returnedCount= returnedCount;
}

public Integer getIssueCount() {
return issueCount;
}

public void setIssueCount(Integer issueCount) {
this.issueCount = issueCount;
}

public Integer getReturnedCount() {
return returnedCount;
}

public void setReturnedCount(Integer returnedCount) {
this.returnedCount = returnedCount;
}
}




Expand Down
Loading