Skip to content

Commit

Permalink
A
Browse files Browse the repository at this point in the history
  • Loading branch information
TungCaoBk97 committed Mar 10, 2020
1 parent f17f94d commit 4eb9073
Show file tree
Hide file tree
Showing 16 changed files with 337 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/main/java/hust/baseweb/baseweb/BasewebApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ public static void main(String[] args) {
@Override
public void run(ApplicationArguments arg0) throws Exception {
System.out.println(UserLogin.PASSWORD_ENCODER.encode("admin"));

}
}
2 changes: 2 additions & 0 deletions src/main/java/hust/baseweb/baseweb/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ protected void configure(HttpSecurity http) throws Exception {
.antMatchers("/api/security/permission",
"/api/security/save-group-permissions")
.hasAuthority("VIEW_EDIT_SECURITY_PERMISSION")
.antMatchers("/api/sales-route/planning-period")
.hasAuthority("VIEW_SALES_ROUTE_PLANNING_PERIOD")
.anyRequest().authenticated()
.and()
.httpBasic().authenticationEntryPoint(authenticationEntryPoint);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package hust.baseweb.baseweb.controller;

import hust.baseweb.baseweb.entity.salesroute.SalesRouteConfig;
import hust.baseweb.baseweb.entity.salesroute.SalesRoutePlanningPeriod;
import hust.baseweb.baseweb.model.GetUserLogin;
import hust.baseweb.baseweb.repository.SalesRoutePlanningPeriodRepository;
import hust.baseweb.baseweb.repository.UserLoginRepository;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;
import java.time.LocalDate;
import java.util.List;

@Getter
@NoArgsConstructor
class CreatePlanningPeriodRequest {
private LocalDate fromDate;
private LocalDate thruDate;
private String description;
}

@Getter
@RequiredArgsConstructor
class CreatePlanningPeriodResponse {
private final List<SalesRoutePlanningPeriod> planningPeriods;
}

@Getter
@NoArgsConstructor
class CreateConfigRequest {
private boolean isEnabled;
private short repeatWeek;
}

@Getter
@RequiredArgsConstructor
class CreateConfigResponse {
private final List<SalesRouteConfig> configs;
}
//@Getter
//@RequiredArgsConstructor
//class CreateConfigRequest {
// private final boolean isEnabled;
// private final short repeatWeek;
//}

@RestController
@AllArgsConstructor(onConstructor = @__(@Autowired))
public class SalesRouteController {
private UserLoginRepository userLoginRepository;
private SalesRoutePlanningPeriodRepository salesRoutePlanningPeriodRepository;

@GetMapping("/api/sales-route/planning-period")
public List<SalesRoutePlanningPeriod> getPlanningPeriod(){
return salesRoutePlanningPeriodRepository.findAll();
}

@PostMapping("/api/sales-route/create-planning-period")
public CreatePlanningPeriodResponse createPlanningPeriod(@RequestBody CreatePlanningPeriodRequest request, Principal principal) {
GetUserLogin getUserLogin = userLoginRepository.getUserLoginByUsername(principal.getName());
SalesRoutePlanningPeriod planningPeriod = new SalesRoutePlanningPeriod(request.getFromDate(), request.getThruDate(),
getUserLogin.getId(), request.getDescription());
salesRoutePlanningPeriodRepository.save(planningPeriod);

List<SalesRoutePlanningPeriod> planningPeriods = salesRoutePlanningPeriodRepository.findAll();
return new CreatePlanningPeriodResponse(planningPeriods);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import hust.baseweb.baseweb.repository.SecurityPermissionRepository;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -28,11 +29,11 @@ class PermissionResponse {
}

@Getter
@RequiredArgsConstructor
@NoArgsConstructor
class SavePermissionsRequest {
private final short securityGroupId;
private final List<Short> toBeInserted;
private final List<Short> toBeDeleted;
private short securityGroupId;
private List<Short> toBeInserted;
private List<Short> toBeDeleted;
}

@Getter
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/hust/baseweb/baseweb/entity/DayOfWeek.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package hust.baseweb.baseweb.entity;

import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
@Getter
@Setter
@RequiredArgsConstructor
public class DayOfWeek {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@NonNull
private short day;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package hust.baseweb.baseweb.entity.salesroute;

import lombok.*;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Date;
import java.util.UUID;

@Entity
@Getter
@Setter
@RequiredArgsConstructor
@NoArgsConstructor
public class SalesRouteConfig {
@Id
private UUID id;

@NonNull
private boolean isEnabled;

@NonNull
private short repeatWeek;

@NonNull
private UUID createdByUserLoginId;

private Date createdAt;
private Date updatedAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package hust.baseweb.baseweb.entity.salesroute;

import lombok.*;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import java.util.Date;

@Entity
@Getter
@Setter
@RequiredArgsConstructor
@NoArgsConstructor
public class SalesRouteConfigDay {
@EmbeddedId
@NonNull
private SalesRouteConfigDayId id;

@Column(insertable = false)
private Date createdAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package hust.baseweb.baseweb.entity.salesroute;

import lombok.*;

import javax.persistence.Embeddable;
import java.io.Serializable;
import java.util.UUID;

@Getter
@Setter
@Embeddable
@EqualsAndHashCode
@RequiredArgsConstructor
@NoArgsConstructor
public class SalesRouteConfigDayId implements Serializable {
@NonNull
private UUID configId;

@NonNull
private short day;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package hust.baseweb.baseweb.entity.salesroute;

import lombok.*;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Date;
import java.util.UUID;

@Entity
@Getter
@Setter
@RequiredArgsConstructor
@NoArgsConstructor
public class SalesRouteDetail {
@Id
private UUID id;

@NonNull
private UUID configId;

@NonNull
private UUID planningPeriodId;

@NonNull
private UUID customerId;

@NonNull
private UUID salesmanId;

private Date createdAt;
private Date updatedAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package hust.baseweb.baseweb.entity.salesroute;

import lombok.*;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.time.LocalDate;
import java.util.Date;
import java.util.UUID;

@Entity
@Getter
@Setter
@RequiredArgsConstructor
@NoArgsConstructor
public class SalesRoutePlanningPeriod {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private UUID id;

@NonNull
private LocalDate fromDate;

@NonNull
private LocalDate thruDate;

@NonNull
private UUID createdByUserLoginId;

@NonNull
private String description;

@CreationTimestamp
private Date createdAt;

@UpdateTimestamp
private Date updatedAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package hust.baseweb.baseweb.entity.salesroute;

import lombok.*;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Date;
import java.util.UUID;

@Entity
@Getter
@Setter
@RequiredArgsConstructor
@NoArgsConstructor
public class SalesmanCheckinHistory {
@Id
@NonNull
private UUID salesRouteDetailId;

private Date checkinTime;
private Date createdAt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package hust.baseweb.baseweb.repository;

import hust.baseweb.baseweb.entity.salesroute.SalesRouteConfigDay;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.UUID;

public interface SalesRouteConfigDayRepository extends JpaRepository<SalesRouteConfigDay, UUID> {
List<SalesRouteConfigDay> findAll();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package hust.baseweb.baseweb.repository;

import hust.baseweb.baseweb.entity.salesroute.SalesRouteConfig;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.UUID;

public interface SalesRouteConfigRepository extends JpaRepository<SalesRouteConfig, UUID> {
List<SalesRouteConfig> findAll();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package hust.baseweb.baseweb.repository;

import hust.baseweb.baseweb.entity.salesroute.SalesRouteDetail;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.UUID;

public interface SalesRouteDetailRepository extends JpaRepository<SalesRouteDetail, UUID> {
List<SalesRouteDetail> findAll();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package hust.baseweb.baseweb.repository;

import hust.baseweb.baseweb.entity.salesroute.SalesRoutePlanningPeriod;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.UUID;

public interface SalesRoutePlanningPeriodRepository extends JpaRepository<SalesRoutePlanningPeriod, UUID> {
List<SalesRoutePlanningPeriod> findAll();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package hust.baseweb.baseweb.repository;

import hust.baseweb.baseweb.entity.salesroute.SalesmanCheckinHistory;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.UUID;

public interface SalesmanCheckinHistoryRepository extends JpaRepository<SalesmanCheckinHistory, UUID> {
List<SalesmanCheckinHistory> findAll();
}

0 comments on commit 4eb9073

Please sign in to comment.