Commit a46bce3e authored by ='s avatar =

-Hieu: register, project_report

parent 0b5c3b02
...@@ -27,6 +27,12 @@ ...@@ -27,6 +27,12 @@
<!-- <groupId>org.springframework.boot</groupId>--> <!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-security</artifactId>--> <!-- <artifactId>spring-boot-starter-security</artifactId>-->
<!-- </dependency>--> <!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
......
package com.itsol.quantrivanphong.access.homepage.controller; //package com.itsol.quantrivanphong.access.homepage.controller;
//
import com.itsol.quantrivanphong.access.homepage.business.CatalogiBusiness; //import com.itsol.quantrivanphong.access.homepage.business.CatalogiBusiness;
import com.itsol.quantrivanphong.access.homepage.business.NewsBusiness; //import com.itsol.quantrivanphong.access.homepage.business.NewsBusiness;
import com.itsol.quantrivanphong.employee.bussiness.EmployeeBussiness; //import com.itsol.quantrivanphong.employee.bussiness.EmployeeBussiness;
import com.itsol.quantrivanphong.exception.ResourceNotFoundException; //import com.itsol.quantrivanphong.exception.ResourceNotFoundException;
import com.itsol.quantrivanphong.model.Employee; //import com.itsol.quantrivanphong.model.Employee;
import com.itsol.quantrivanphong.model.News; //import com.itsol.quantrivanphong.model.News;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; //import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; //import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity; //import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; //import org.springframework.web.bind.annotation.*;
//
import javax.validation.Valid; //import javax.validation.Valid;
import java.util.List; //import java.util.List;
//
@RestController //@RestController
@RequestMapping("/api") //@RequestMapping("/api")
public class NewsController { //public class NewsController {
@Autowired // @Autowired
private NewsBusiness newsBusiness; // private NewsBusiness newsBusiness;
//
@Autowired // @Autowired
private CatalogiBusiness catalogiBusiness; // private CatalogiBusiness catalogiBusiness;
//
@Autowired // @Autowired
private EmployeeBussiness employeeBusiness; // private EmployeeBussiness employeeBusiness;
// get All news // // get All news
@GetMapping("/news") // @GetMapping("/news")
public ResponseEntity<List<News>> getAllNews(){ // public ResponseEntity<List<News>> getAllNews(){
return ResponseEntity.ok(newsBusiness.findAllNews()); // return ResponseEntity.ok(newsBusiness.findAllNews());
} // }
//
// get news by employeeId // // get news by employeeId
@GetMapping("/news/employees/{employeeId}") // @GetMapping("/news/employees/{employeeId}")
public List<News> getAllNewsByEmployeeId(@PathVariable(value = "employeeId") int employeeId) { // public List<News> getAllNewsByEmployeeId(@PathVariable(value = "employeeId") int employeeId) {
return newsBusiness.findByEmployeeId(employeeId); // return newsBusiness.findByEmployeeId(employeeId);
} // }
// get News by catalogiId // // get News by catalogiId
@GetMapping("/news/catalogi/{catalogiId}") // @GetMapping("/news/catalogi/{catalogiId}")
public List<News> getAllNewsByCatalogiId(@PathVariable(value="catalogiId") int catalogiId){ // public List<News> getAllNewsByCatalogiId(@PathVariable(value="catalogiId") int catalogiId){
return newsBusiness.findByCatalogiId(catalogiId); // return newsBusiness.findByCatalogiId(catalogiId);
} // }
//
//
// create news by employeesId // // create news by employeesId
@PostMapping("/news/employees/{employeeId}") // @PostMapping("/news/employees/{employeeId}")
public News createNews(@PathVariable (value = "employeeId") int employeeId, // public News createNews(@PathVariable (value = "employeeId") int employeeId,
@Valid @RequestBody News news) { // @Valid @RequestBody News news) {
return employeeBusiness.findById(employeeId).map(employee -> { // return employeeBusiness.findById(employeeId).map(employee -> {
news.setEmployee(employee); // news.setEmployee(employee);
return newsBusiness.save(news); // return newsBusiness.save(news);
}).orElseThrow(() -> new ResourceNotFoundException("Employee" ,"employeeId",employeeId)); // }).orElseThrow(() -> new ResourceNotFoundException("Employee" ,"employeeId",employeeId));
} // }
//
// Edit news by EmployeeId // // Edit news by EmployeeId
@PutMapping("/employees/{employeeId}/news/{newsId}") // @PutMapping("/employees/{employeeId}/news/{newsId}")
public News updateNews(@PathVariable (value = "employeeId") int employeeId, // public News updateNews(@PathVariable (value = "employeeId") int employeeId,
@PathVariable (value = "newsId") int newsId, // @PathVariable (value = "newsId") int newsId,
@Valid @RequestBody News newsRequest) { // @Valid @RequestBody News newsRequest) {
if(!employeeBusiness.findById(employeeId).isPresent()) { // if(!employeeBusiness.findById(employeeId).isPresent()) {
throw new ResourceNotFoundException("Employee" ,"employeeId",employeeId); // throw new ResourceNotFoundException("Employee" ,"employeeId",employeeId);
} // }
if (!newsBusiness.findById(newsId).isPresent()) { // if (!newsBusiness.findById(newsId).isPresent()) {
throw new ResourceNotFoundException("News", "id", newsId); // throw new ResourceNotFoundException("News", "id", newsId);
} // }
return newsBusiness.updateNews(newsId,newsRequest); // return newsBusiness.updateNews(newsId,newsRequest);
} // }
//
//delete news by employeeId and newsId // //delete news by employeeId and newsId
@DeleteMapping("/employees/{employeeId}/news/{newsId}") // @DeleteMapping("/employees/{employeeId}/news/{newsId}")
public ResponseEntity<?> deleteNews(@PathVariable (value = "employeeId") int employeeId, // public ResponseEntity<?> deleteNews(@PathVariable (value = "employeeId") int employeeId,
@PathVariable (value = "newsId") int newsId) { // @PathVariable (value = "newsId") int newsId) {
if(!newsBusiness.findByIdAndEmployeeId(employeeId,newsId).isPresent()){ // if(!newsBusiness.findByIdAndEmployeeId(employeeId,newsId).isPresent()){
throw new ResourceNotFoundException("News","newsId",newsId); // throw new ResourceNotFoundException("News","newsId",newsId);
} // }
return ResponseEntity.ok(newsBusiness.deleteNews(employeeId,newsId)); // return ResponseEntity.ok(newsBusiness.deleteNews(employeeId,newsId));
} // }
} //}
package com.itsol.quantrivanphong.access.register.bussiness;
import com.itsol.quantrivanphong.access.register.dto.EmailDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
@Component
public class EmailBussiness {
@Autowired
private JavaMailSender sender;
public boolean sendEmail(EmailDTO emailDTO) {
boolean check;
// MimeMessage message = sender.createMimeMessage();
// MimeMessageHelper helper = new MimeMessageHelper(message);
//
//
// try {
// helper.setTo(emailDTO.getRecipientEmail());
// helper.setText(emailDTO.getMessage(),"text/html");
// helper.setSubject(emailDTO.getSubject());
// sender.send(message);
// check = true;
// } catch (Exception e) {
// e.printStackTrace();
// check = false;
// }
// Recipient's email ID needs to be mentioned.
String to = emailDTO.getRecipientEmail();
// Sender's email ID needs to be mentioned
String from = "hieunv2496@gmail.com";
final String username = "hieunv2496@gmail.com";//change accordingly
final String password = "anhieu1996";//change accordingly
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
// Get the Session object.
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
// Create license default MimeMessage object.
Message message = new MimeMessage(session);
// Set From: header field of the header.
message.setFrom(new InternetAddress(from));
// Set To: header field of the header.
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to));
// Set Subject: header field
message.setSubject(emailDTO.getSubject());
// Send the actual HTML message, as big as you like
message.setContent(
emailDTO.getMessage(),
"text/html");
// Send message
Transport.send(message);
System.out.println("Sent message successfully....");
} catch (MessagingException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
return true;
}
}
package com.itsol.quantrivanphong.access.register.bussiness;
import com.itsol.quantrivanphong.access.register.dto.EmailDTO;
import com.itsol.quantrivanphong.access.register.dto.VerifyDTO;
import com.itsol.quantrivanphong.access.register.repository.RegisterRepository;
import com.itsol.quantrivanphong.model.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.nio.charset.Charset;
import java.util.Random;
@Service
public class GeneratePasswordBussiness {
@Autowired
private RegisterRepository registerRepository;
@Autowired
private EmailBussiness emailBussiness;
public String getAlphaNumericString(){
// length is bounded by 256 Character
byte[] array = new byte[256];
new Random().nextBytes(array);
int n = 8;
String randomString = new String(array, Charset.forName("UTF-8"));
// Create license StringBuffer to store the result
StringBuffer pass = new StringBuffer();
// Append first 20 alphanumeric characters
// from the generated random String into the result
for (int k = 0; k < randomString.length(); k++) {
char ch = randomString.charAt(k);
if (((ch >= 'a' && ch <= 'z')
|| (ch >= 'A' && ch <= 'Z')
|| (ch >= '0' && ch <= '9'))
&& (n > 0)) {
pass.append(ch);
n--;
}
}
return pass.toString();
}
public String insertPassword(String username){
String mess;
Employee employee = registerRepository.findByUsername(username);
if(employee == null){
mess = "Không tìm thấy Username";
}else {
if(employee.isStatus()) {
mess = "Tài khoản đã được kích hoạt từ trước";
}else {
VerifyDTO verifyDTO = new VerifyDTO();
verifyDTO.setId(employee.getId());
verifyDTO.setPassword(getAlphaNumericString());
verifyDTO.setEmailAddress(employee.getEmailAddress());
verifyDTO.setStatus(true);
registerRepository.insertPassword(verifyDTO.getPassword(),verifyDTO.isStatus(),verifyDTO.getId());
EmailDTO emailDTO = new EmailDTO();
emailDTO.setSubject("Your Password");
emailDTO.setMessage("Your password is: "+verifyDTO.getPassword()+ " You are ready to login!!!!");
emailDTO.setRecipientEmail(verifyDTO.getEmailAddress());
emailBussiness.sendEmail(emailDTO);
mess = "Kích hoạt thành công, kiểm tra email để lấy mật khẩu.";
}
}
return mess;
}
}
package com.itsol.quantrivanphong.access.register.bussiness;
public class InputException extends Exception {
public InputException(String message){
super(message);
}
@Override
public String getMessage() {
return "Lỗi: "+super.getMessage();
}
}
package com.itsol.quantrivanphong.access.register.bussiness; package com.itsol.quantrivanphong.access.register.bussiness;
import com.itsol.quantrivanphong.access.register.dto.EmailDTO;
import com.itsol.quantrivanphong.access.register.dto.RegisterDTO;
import com.itsol.quantrivanphong.access.register.repository.RegisterRepository;
import com.itsol.quantrivanphong.model.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class RegisterBussiness { public class RegisterBussiness {
@Autowired
private RegisterRepository registerRepository;
@Autowired
private EmailBussiness emailBussiness;
public String register(RegisterDTO registerDTO) {
String mess;
//lấy thông tin employee trong DB thông qua usernameDTO
Employee employee = registerRepository.findByUsername(registerDTO.getUsername());
//Nếu Username không tồn tại thì cho đăng ký
if (employee == null){
//Kiểm tra Email được đăng ký hay chưa
Employee employee1 = registerRepository.findByEmailAddress(registerDTO.getEmailAddress());
if (employee1 == null){
Employee employee2 = new Employee();
//Đổ dữ liệu từ DTO vào Empl
employee2.setUsername(registerDTO.getUsername());
employee2.setFirstName(registerDTO.getFirstName());
employee2.setLastName(registerDTO.getLastName());
employee2.setPicture(registerDTO.getPicture());
employee2.setEmailAddress(registerDTO.getEmailAddress());
employee2.setPhoneNumber(String.valueOf(registerDTO.getPhoneNumber()));
employee2.setSkype(registerDTO.getSkype());
employee2.setFacebookProfile(registerDTO.getFacebookProfile());
employee2.setPosition(registerDTO.getPosition());
employee2.setHomeTown(registerDTO.getHomeTown());
employee2.setEducation(registerDTO.getEducation());
employee2.setSchool(registerDTO.getSchool());
employee2.setDepartment(registerDTO.getDepartment());
employee2.setGraduationYear(String.valueOf(registerDTO.getGraduationYear()));
employee2.setChecked(false);
employee2.setStatus(false);
//Xử lý việc thêm mới
Employee employee3 = registerRepository.save(employee2);
if (employee3 != null){
EmailDTO emailDTO = new EmailDTO();
emailDTO.setRecipientEmail(employee3.getEmailAddress());
emailDTO.setMessage("Link: <a href = 'http://localhost:8081/verify/"+employee3.getUsername()+"'> Register verify account...</a>");
emailDTO.setUsername(employee3.getUsername());
emailDTO.setSubject("Confirm register:"+employee3.getUsername());
emailBussiness.sendEmail(emailDTO);
mess = "Đk thành công => Check email xác nhận mật khẩu";
}else {
mess = "ĐK không thành công";
}
}else {
mess = "Email đã được đăng ký với tài khoản khác chọn lại email";
}
//Nếu Username tồn tại
}else {
//Kiểm tra tiếp email nếu tồn tại
if (employee.getEmailAddress().equals(registerDTO.getEmailAddress())){
//Kiểm tra tiếp trạng thái kích hoạt
if (employee.isStatus()){
mess = "Username đã tồn tại => Đăng nhập";
}else {
mess = "Username đã tồn tại => Kích hoạt";
}
//Nếu email không tồn tại
}else {
mess = "username đã tồn tại chọn username khác!";
}
}
return mess;
}
} }
package com.itsol.quantrivanphong.access.register.controller; package com.itsol.quantrivanphong.access.register.controller;
import com.itsol.quantrivanphong.access.register.bussiness.InputException;
import com.itsol.quantrivanphong.access.register.bussiness.RegisterBussiness;
import com.itsol.quantrivanphong.access.register.dto.RegisterDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.InputMismatchException;
@RestController
@RequestMapping(path = "/user")
public class RegisterController { public class RegisterController {
@Autowired
private RegisterBussiness registerBussiness;
@PostMapping(path = "/register", consumes = "application/json", produces = "application/json")
public String register(@RequestBody RegisterDTO registerDTO) {
String mess ;
try {
if(registerDTO.getUsername().trim().equals("")) throw new InputException("Username is not null");
if(registerDTO.getUsername().length()< 5 || registerDTO.getUsername().length() > 18) throw new InputException("Username in 5 - 18 characters");
if(registerDTO.getLastName().equals("")) throw new InputException("Last name is not null");
if(registerDTO.getEmailAddress().equals("")) throw new InputException("Email address is not null");
if(registerDTO.getGraduationYear() < 0) throw new InputException("lỗi năm < 0") ;
mess = registerBussiness.register(registerDTO);
}catch (InputException e){
mess = e.getMessage();
}catch (InputMismatchException e){
mess = e.getMessage();
}catch (Exception e){
mess = e.getMessage();
}
return mess;
}
} }
package com.itsol.quantrivanphong.access.register.controller;
import com.itsol.quantrivanphong.access.register.bussiness.GeneratePasswordBussiness;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(path = "/verify")
public class VerifyAccountController {
@Autowired
private GeneratePasswordBussiness generatePasswordBussiness;
@GetMapping(path = "/{username}")
public String verifyPassword(@PathVariable("username") String username){
String mess = generatePasswordBussiness.insertPassword(username);
return mess;
}
}
package com.itsol.quantrivanphong.access.register.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class EmailDTO {
private String subject;
private String message;
private String username;
private String recipientEmail;
}
package com.itsol.quantrivanphong.access.register.dto; package com.itsol.quantrivanphong.access.register.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RegisterDTO { public class RegisterDTO {
private String username;
private String firstName;
private String lastName;
private String picture;
private String emailAddress;
private int phoneNumber;
private String skype;
private String facebookProfile;
private String position;
private String homeTown;
private String education;
private String school;
private String department;
private int graduationYear;
} }
package com.itsol.quantrivanphong.access.register.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class VerifyDTO {
private int id;
private String password;
private String emailAddress;
private boolean status;
}
package com.itsol.quantrivanphong.access.register.repository; package com.itsol.quantrivanphong.access.register.repository;
import com.itsol.quantrivanphong.model.ProjectReport;
import com.itsol.quantrivanphong.model.Employee;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
public interface RegisterRepository extends JpaRepository<ProjectReport, Integer> { public interface RegisterRepository extends JpaRepository<Employee, Integer> {
Employee findByUsername(String username);
Employee findByEmailAddress(String emailAddress);
@Transactional
@Modifying(clearAutomatically = true)
@Query(value = "UPDATE employee e SET e.password = ?1, e.status = ?2 where e.id = ?3", nativeQuery = true)
void insertPassword(String password, boolean status, int id);
} }
...@@ -23,7 +23,7 @@ public abstract class DateAudit implements Serializable { ...@@ -23,7 +23,7 @@ public abstract class DateAudit implements Serializable {
private Instant createdAt; private Instant createdAt;
@LastModifiedDate @LastModifiedDate
@Column(nullable = false) @Column(nullable = false, columnDefinition = "null")
private Instant updatedAt; private Instant updatedAt;
public Instant getCreatedAt() { public Instant getCreatedAt() {
......
package com.itsol.quantrivanphong.employee.bussiness;
import com.itsol.quantrivanphong.employee.repository.EmployeeRepository;
import com.itsol.quantrivanphong.model.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Optional;
@Service
public class EmployeeBussiness {
@Autowired
EmployeeRepository employeeRepository;
// public List<Employee> findAll(){
// return employeeRepository.findAll();
// }
//
public Optional<Employee> findById(int newsId){
return employeeRepository.findById(newsId);
}
// public User save(User user){
// return userRepository.save(user);
// }
// public User updateUser(Long newsId, User signUpDTO){
// User user = userRepository.findUserById(newsId);
// user.setUsername(signUpDTO.getUsername());
// user.setPassword(signUpDTO.getPassword());
// user.setEmail(signUpDTO.getEmail());
// user.setFullname(signUpDTO.getFullname());
// user.setImage(signUpDTO.getImage());
// user.setKnowledge(signUpDTO.getKnowledge());
// user.setUniversity(signUpDTO.getUniversity());
// user.setPhonenumber(signUpDTO.getPhonenumber());
// user.setPosition(signUpDTO.getPosition());
// user.setVillage(signUpDTO.getVillage());
// user.setYearOfGraduation(signUpDTO.getYearOfGraduation());
// user.setRole(signUpDTO.getRole());
// return userRepository.save(user);
// }
//
// public void deleteUser(Long newsId){
// userRepository.deleteById(newsId);
// }
}
//package com.itsol.quantrivanphong.employee.controller;
//
//import com.example.easynotes.exception.ResourceNotFoundException;
//import com.example.easynotes.login.model.User;
//import com.example.easynotes.users.bussiness.UserBussiness;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//
//import javax.validation.Valid;
//import java.util.List;
//
//@RestController
//@RequestMapping("/api")
//public class UserController {
//
// @Autowired
// private UserBussiness userBussiness;
//
// @GetMapping("/users")
// public List<User> getAllUser(){ return userBussiness.findAll();}
//
// @GetMapping("/users/{id}")
// public User getUserById(@PathVariable(value = "id") Long userId){
// return userBussiness.findById(userId).orElseThrow(()-> new ResourceNotFoundException("News", "id", userId));
// }
//
// @PutMapping("/users/{id}")
// public ResponseEntity<User> updateUser(@PathVariable(value = "id") Long userId,
// @Valid @RequestBody User userDetails) {
// if (!userBussiness.findById(userId).isPresent()) {
// throw new ResourceNotFoundException("User", "id", userId);
// }
// return ResponseEntity.ok(userBussiness.updateUser(userId,userDetails));
// }
//}
package com.itsol.quantrivanphong.employee.repository;
import com.itsol.quantrivanphong.model.Employee;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface EmployeeRepository extends JpaRepository<Employee,Integer> {
@Query("SELECT u FROM Employee u where u.id=:id")
Employee findEmployeeById(int id);
}
package com.itsol.quantrivanphong.report.reportdetail.bussiness; package com.itsol.quantrivanphong.manager.reportdetail.bussiness;
import com.itsol.quantrivanphong.manager.reportdetail.dto.request.ReportDTO;
import com.itsol.quantrivanphong.manager.reportdetail.dto.response.ReportResponseDTO;
import com.itsol.quantrivanphong.manager.reportdetail.repository.EmployeeRepository;
import com.itsol.quantrivanphong.manager.reportdetail.repository.ProjectReportRepository;
import com.itsol.quantrivanphong.manager.reportdetail.repository.ProjectRepository;
import com.itsol.quantrivanphong.model.Project; import com.itsol.quantrivanphong.model.Project;
import com.itsol.quantrivanphong.report.reportdetail.dto.request.ReportDTO; import com.itsol.quantrivanphong.model.ProjectReport;
import com.itsol.quantrivanphong.report.reportdetail.dto.response.ReportResponseDTO;
import com.itsol.quantrivanphong.report.reportdetail.repository.EmployeeRepository;
import com.itsol.quantrivanphong.report.reportdetail.repository.ProjectRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -18,25 +21,30 @@ public class ReportProjectBussiness { ...@@ -18,25 +21,30 @@ public class ReportProjectBussiness {
@Autowired @Autowired
private EmployeeRepository employeeRepository; private EmployeeRepository employeeRepository;
@Autowired
private ProjectReportRepository projectReportRepository;
public List<Project> listProjectWorking(){
public List<Project> listProjectIsTrue(){ List<Project> projectList = projectRepository.listProjectWorking();
List<Project> projectList = projectRepository.listProjectIsTrue();
if(projectList.isEmpty()){ if(projectList.isEmpty()){
return null; return null;
}else }else
return projectList; return projectList;
} }
public ReportResponseDTO reportProjectDetail(ReportDTO reportDTO){ public List<ProjectReport> allProjectReport(ReportDTO reportDTO){
List<ProjectReport> projectReportList = projectReportRepository.allProjectReport(reportDTO.getProjectId());
if (projectReportList.isEmpty()){
return null;
}else
return projectReportList;
}
ReportResponseDTO rd = new ReportResponseDTO(); public ProjectReport latestReport(ReportDTO reportDTO){
rd.setProjectId(reportDTO.getProjectId());
rd.setProjectName(projectRepository.ProjectName(reportDTO.getProjectId()));
rd.setTeamLeadList(employeeRepository.findTeamLeadPosition(reportDTO.getProjectId()));
rd.setMemberList(employeeRepository.findMemberPosition(reportDTO.getProjectId()));
rd.setFirstPoint(reportDTO.getFirstPoint());
rd.setFinalPoint(reportDTO.getFinalPoint());
return rd; return projectReportRepository.latestReport(reportDTO.getProjectId());
} }
} }
package com.itsol.quantrivanphong.report.reportdetail.controller; package com.itsol.quantrivanphong.manager.reportdetail.controller;
import com.itsol.quantrivanphong.manager.reportdetail.bussiness.ReportProjectBussiness;
import com.itsol.quantrivanphong.manager.reportdetail.dto.request.ReportDTO;
import com.itsol.quantrivanphong.model.Project; import com.itsol.quantrivanphong.model.Project;
import com.itsol.quantrivanphong.report.reportdetail.bussiness.ReportProjectBussiness; import com.itsol.quantrivanphong.model.ProjectReport;
import com.itsol.quantrivanphong.report.reportdetail.dto.request.ReportDTO;
import com.itsol.quantrivanphong.report.reportdetail.dto.response.ReportResponseDTO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
...@@ -20,14 +20,20 @@ public class ReportProjectController { ...@@ -20,14 +20,20 @@ public class ReportProjectController {
private ReportProjectBussiness reportProjectBussiness; private ReportProjectBussiness reportProjectBussiness;
@GetMapping(path = "/project/all",consumes = "application/json", produces = "application/json") @GetMapping(path = "/project/all",consumes = "application/json", produces = "application/json")
public ResponseEntity<List<Project>> listProjectIsTrue(){ public ResponseEntity<List<Project>> listProjectWorking(){
List<Project> projectList = reportProjectBussiness.listProjectWorking();
return ResponseEntity.ok(reportProjectBussiness.listProjectIsTrue()); return ResponseEntity.ok(projectList);
} }
@GetMapping(path = "/project/id",consumes = "application/json", produces = "application/json") @GetMapping(path = "/project/latest",consumes = "application/json", produces = "application/json")
public ResponseEntity<ReportResponseDTO> reportProjectDetail(@RequestBody ReportDTO reportDTO){ public ResponseEntity<ProjectReport> latestReport(@RequestBody ReportDTO reportDTO){
ProjectReport projectReport = reportProjectBussiness.latestReport(reportDTO);
return ResponseEntity.ok(projectReport);
}
return ResponseEntity.ok(reportProjectBussiness.reportProjectDetail(reportDTO)); @GetMapping(path = "/project/allReport",consumes = "application/json", produces = "application/json")
public ResponseEntity<List<ProjectReport>> allProjectReport(@RequestBody ReportDTO reportDTO){
List<ProjectReport> projectReportList = reportProjectBussiness.allProjectReport(reportDTO);
return ResponseEntity.ok(projectReportList);
} }
} }
package com.itsol.quantrivanphong.report.reportdetail.dto.request; package com.itsol.quantrivanphong.manager.reportdetail.dto.request;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
......
package com.itsol.quantrivanphong.report.reportdetail.dto.response; package com.itsol.quantrivanphong.manager.reportdetail.dto.response;
import com.itsol.quantrivanphong.model.Employee; import com.itsol.quantrivanphong.model.Employee;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
......
package com.itsol.quantrivanphong.manager.reportdetail.repository;
import com.itsol.quantrivanphong.model.Employee;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface EmployeeRepository extends JpaRepository<Employee,Integer> {
//new
// @Query(value = "SELECT e.username FROM employee e JOIN eproject ep ON e.id = ep.employee_id JOIN project p ON ep.project_id = p.id WHERE p.id = ?1 AND ep.position = 'team_lead' GROUP BY e.id",nativeQuery = true)
// String findTeamLeader(int projectId);
//
// @Query(value = "SELECT COUNT(e.id)FROM employee e JOIN eproject ep ON e.id = ep.employee_id JOIN project p ON ep.project_id = p.id WHERE p.id = ?1 AND ep.position = 'member'", nativeQuery = true)
// int numberOfMember(int projectId);
}
package com.itsol.quantrivanphong.manager.reportdetail.repository;
import com.itsol.quantrivanphong.model.ProjectReport;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface ProjectReportRepository extends JpaRepository<ProjectReport, Integer> {
@Query(value = "SELECT * FROM project_report pr WHERE pr.project_id = ?1 ORDER BY pr.created_at DESC limit 1", nativeQuery = true)
ProjectReport latestReport(int projectId);
@Query(value = "SELECT * FROM project_report pr WHERE pr.project_id = ?1 ORDER BY pr.created_at DESC", nativeQuery = true)
List<ProjectReport> allProjectReport(int projectId);
}
package com.itsol.quantrivanphong.report.reportdetail.repository; package com.itsol.quantrivanphong.manager.reportdetail.repository;
import com.itsol.quantrivanphong.model.Employee;
import com.itsol.quantrivanphong.model.Project; import com.itsol.quantrivanphong.model.Project;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
...@@ -10,10 +9,10 @@ import java.util.List; ...@@ -10,10 +9,10 @@ import java.util.List;
public interface ProjectRepository extends JpaRepository<Project, Integer> { public interface ProjectRepository extends JpaRepository<Project, Integer> {
@Query(value = "SELECT p.id, p.name, p.descriptions, p.start_date, p.end_date, p.status FROM project p where p.status = 2", nativeQuery = true) @Query(value = "SELECT p.id, p.name, p.descriptions, p.start_date, p.end_date, p.status FROM project p where p.status = 2", nativeQuery = true)
List<Project> listProjectIsTrue(); List<Project> listProjectWorking();
@Query(value = "SELECT p.name FROM project p where p.id = ?1", nativeQuery = true) // @Query(value = "SELECT p.name FROM project p where p.id = ?1", nativeQuery = true)
String ProjectName(int projectId); // String ProjectName(int projectId);
......
package com.itsol.quantrivanphong.report.reportdetail.repository; package com.itsol.quantrivanphong.manager.reportdetail.repository;
import com.itsol.quantrivanphong.model.ProjectReport; import com.itsol.quantrivanphong.model.ProjectReport;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface ReportDetailRepository extends JpaRepository<ProjectReport, Integer> { public interface ReportDetailRepository extends JpaRepository<ProjectReport, Integer> {
// @Query(value = "SELECT * FROM project_report pr ", nativeQuery = true)
// String ProjectName(int projectId);
} }
package com.itsol.quantrivanphong.manager.reportdetail;
public class test {
}
...@@ -25,7 +25,7 @@ public class Employee { ...@@ -25,7 +25,7 @@ public class Employee {
@Column(name = "username", length = 128, nullable = false, unique = true) @Column(name = "username", length = 128, nullable = false, unique = true)
private String username; private String username;
@Column(name = "password", length = 128, nullable = false) @Column(name = "password", length = 128)
private String password; private String password;
@Column(name = "first_name", length = 50) @Column(name = "first_name", length = 50)
......
...@@ -14,8 +14,7 @@ import javax.persistence.*; ...@@ -14,8 +14,7 @@ import javax.persistence.*;
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@EntityListeners(AuditingEntityListener.class) @EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value = {"createdAt", "updatedAt"}, @JsonIgnoreProperties(value = {"createdAt", "updatedAt"},allowGetters = true)
allowGetters = true)
@Table(name = "news") @Table(name = "news")
public class News extends DateAudit { public class News extends DateAudit {
......
package com.itsol.quantrivanphong.model; package com.itsol.quantrivanphong.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.itsol.quantrivanphong.audit.DateAudit;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*; import javax.persistence.*;
...@@ -10,25 +13,30 @@ import javax.persistence.*; ...@@ -10,25 +13,30 @@ import javax.persistence.*;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Entity @Entity
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value = {"createdAt", "updatedAt"},allowGetters = true)
@Table(name = "project_report") @Table(name = "project_report")
public class ProjectReport { public class ProjectReport extends DateAudit {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, unique = true) @Column(name = "id", nullable = false, unique = true)
private int id; private int id;
@Column(name = "title") @Column(name = "project_name")
private String title; private String projectName;
@Column(name = "content") @Column(name = "team_leader")
private String content; private String teamLeader;
@Column(name = "note") @Column(name = "number_of_members")
private String note; private int numberOfMember;
@Column(name = "checked") @Column(name = "calendar_effort")
private String checked; private int calendarEffort;
@Column(name = "lack_of_reports")
private int lackOfReport;
@Column(name = "status") @Column(name = "status")
private boolean status; private boolean status;
......
package com.itsol.quantrivanphong.model; package com.itsol.quantrivanphong.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.itsol.quantrivanphong.audit.DateAudit;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*; import javax.persistence.*;
...@@ -10,8 +13,10 @@ import javax.persistence.*; ...@@ -10,8 +13,10 @@ import javax.persistence.*;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Entity @Entity
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value = {"createdAt", "updatedAt"},allowGetters = true)
@Table(name = "timesheet") @Table(name = "timesheet")
public class TimeSheet { public class TimeSheet extends DateAudit {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
......
package com.itsol.quantrivanphong.report.reportdetail.repository;
import com.itsol.quantrivanphong.model.Employee;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface EmployeeRepository extends JpaRepository<Employee, Integer> {
@Query(value = "SELECT * FROM employee e JOIN eproject ep ON e.id = ep.employee_id JOIN project p ON ep.project_id = p.id WHERE p.id = ?1 AND ep.position = 'team_lead' GROUP BY e.id",nativeQuery = true)
List<Employee> findTeamLeadPosition(int projectId);
@Query(value = "SELECT * FROM employee e JOIN eproject ep ON e.id = ep.employee_id JOIN project p ON ep.project_id = p.id WHERE p.id = ?1 AND ep.position = 'member' GROUP BY e.id",nativeQuery = true)
List<Employee> findMemberPosition(int projectId);
}
#server.port=8081 server.port=8081
# =============================== # ===============================
# DATABASE CONNECTION # DATABASE CONNECTION
# =============================== # ===============================
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/quantrivanphong spring.datasource.url=jdbc:mysql://localhost:3306/quantrivanphong
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=vanloc spring.datasource.password=
# =============================== # ===============================
# JPA / HIBERNATE # JPA / HIBERNATE
...@@ -16,17 +16,13 @@ spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialec ...@@ -16,17 +16,13 @@ spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialec
#spring.jpa.properties.hibernate.default_schema=qlns_itsol #spring.jpa.properties.hibernate.default_schema=qlns_itsol
## Fix Postgres JPA Error:
## Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented.
#spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
# =============================== # ===============================
# SEND EMAIL # SEND EMAIL
# ============================== # ==============================
spring.mail.host=smtp.gmail.com spring.mail.host=smtp.gmail.com
spring.mail.port=587 spring.mail.port=587
spring.mail.username= spring.mail.username=hieunv2496@gmail.com
spring.mail.password= spring.mail.password=anhieu1996
spring.mail.properties.mail.smtp.starttls.enable=true spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.auth=true
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment