Compare commits
No commits in common. 'jiangzhuochen' and 'main' have entirely different histories.
jiangzhuoc
...
main
@ -1,73 +0,0 @@
|
||||
package crm.controller;
|
||||
|
||||
import crm.entity.Customer;
|
||||
import crm.service.CustomerService;
|
||||
import crm.utils.WriteCsvToResponse;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
public class CSVController {
|
||||
|
||||
private CustomerService customerService;
|
||||
|
||||
public CSVController(CustomerService customerService) {
|
||||
this.customerService = customerService;
|
||||
}
|
||||
|
||||
@GetMapping(value = "/customers", produces = "text/csv")
|
||||
public void findCustomers(HttpServletResponse httpServletResponse) throws IOException {
|
||||
List<Customer> customers = (List<Customer>) customerService.listAllCustomers();
|
||||
WriteCsvToResponse.writeCustomers(httpServletResponse.getWriter(), customers);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/customers/{id}", produces = "text/csv")
|
||||
public void findCustomer(@PathVariable Long id, HttpServletResponse httpServletResponse) throws IOException {
|
||||
Customer customer = customerService.showCustomer(id);
|
||||
WriteCsvToResponse.writeCustomer(httpServletResponse.getWriter(), customer);
|
||||
}
|
||||
|
||||
// @GetMapping("/show-import")
|
||||
// public String showImportCsvSite() {
|
||||
// return "csv/import";
|
||||
// }
|
||||
|
||||
/*@GetMapping("/import")
|
||||
public String processRequestImportCsv(Model model) {
|
||||
File document = ReadDataUtils.ReadFile("Select CSV file", null, "Only CSV Files", "csv");
|
||||
// System.out.println(document.getName());
|
||||
|
||||
CSVReader reader;
|
||||
List<String[]> data = new ArrayList<>();
|
||||
try {
|
||||
reader = new CSVReader(new FileReader(document));
|
||||
String[] line;
|
||||
while ((line = reader.readNext()) != null) {
|
||||
// System.out.println(line[1] + "\t" + line[2]);
|
||||
data.add(line);
|
||||
// if(line[1].equals("QUICK SUB")){
|
||||
// System.out.println(line[0] + "\t" + line[1] + "\t" + line[2]);
|
||||
// }
|
||||
}
|
||||
model.addAttribute("data", data);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
*//*System.out.println(data.get(0)[1] + "\t" + data.get(0)[2]);
|
||||
System.out.println(data.get(1)[1] + "\t" + data.get(1)[2]);*//*
|
||||
|
||||
return "csv/show";
|
||||
}*/
|
||||
|
||||
// @GetMapping("/show")
|
||||
// public String showPageWithCsvImported(@ModelAttribute List<String[]> data) {
|
||||
// data.
|
||||
// return "csv/show";
|
||||
// }
|
||||
|
||||
}
|
||||
@ -1,504 +0,0 @@
|
||||
package crm.controller;
|
||||
|
||||
import crm.entity.Contract;
|
||||
import crm.entity.Customer;
|
||||
import crm.entity.User;
|
||||
import crm.service.ContractService;
|
||||
import crm.service.CustomerService;
|
||||
import crm.service.UserService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/contract")
|
||||
public class ContractController {
|
||||
|
||||
private ContractService contractService;
|
||||
|
||||
private CustomerService customerService;
|
||||
|
||||
private UserService userService;
|
||||
|
||||
public ContractController(ContractService contractService, CustomerService customerService, UserService userService) {
|
||||
this.contractService = contractService;
|
||||
this.customerService = customerService;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/list
|
||||
* <p>
|
||||
* Shows all contracts
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return contract/list
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public String showAllContracts(Model model) {
|
||||
model.addAttribute("contracts", contractService.listAllContracts());
|
||||
return "contract/list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/add
|
||||
* <p>
|
||||
* Shows add contract form
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return contract/add
|
||||
*/
|
||||
@GetMapping("/add")
|
||||
public String showFormAddContract(Model model) {
|
||||
Iterable<Customer> customers = customerService.findAllByEnabledTrue();
|
||||
Iterable<User> users = userService.listAllUsers();
|
||||
model.addAttribute("contract", new Contract());
|
||||
model.addAttribute("customers", customers);
|
||||
model.addAttribute("users", users);
|
||||
return "contract/add";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/add
|
||||
* <p>
|
||||
* Processes add contract request
|
||||
*
|
||||
* @param contract variable type Contract
|
||||
* @param bindingResult variable type BindingResult
|
||||
* @return contract/success
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public String processRequestAddContract(@Valid Contract contract, BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
return "redirect:/contract/add";
|
||||
} else {
|
||||
contractService.saveContract(contract);
|
||||
return "contract/success";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/edit/{id}
|
||||
* <p>
|
||||
* Shows edit contract form
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @param id variable type long contract id
|
||||
* @return contract/edit
|
||||
*/
|
||||
@GetMapping("/edit/{id}")
|
||||
public String showFormEditContract(Model model, @PathVariable Long id) {
|
||||
model.addAttribute("contract", contractService.showContract(id));
|
||||
return "contract/edit";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/edit/{id}
|
||||
* <p>
|
||||
* Processes edit contract request
|
||||
*
|
||||
* @param id variable type long contract id
|
||||
* @param contract variable type Contract
|
||||
* @param bindingResult variable type BindingResult
|
||||
* @return redirect:/contract/list
|
||||
*/
|
||||
@PostMapping("/edit/{id}")
|
||||
public String processRequestEditContract(@PathVariable Long id, @Valid Contract contract,
|
||||
BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
return "redirect:/contract/edit/" + id;
|
||||
} else {
|
||||
contractService.saveContract(contract);
|
||||
return "redirect:/contract/list";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/name-search
|
||||
* <p>
|
||||
* Shows form to search contract by name
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return contract/name-search
|
||||
*/
|
||||
@GetMapping("/name-search")
|
||||
public String showNameSearchForm(Model model) {
|
||||
model.addAttribute("contract", new Contract());
|
||||
return "contract/name-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/name-search
|
||||
* <p>
|
||||
* Processes request searching by name
|
||||
*
|
||||
* @param contract variable type Contract
|
||||
* @param model model to add attributes to
|
||||
* @return contract/show
|
||||
*/
|
||||
@PostMapping("/name-search")
|
||||
public String processRequestNameSearch(@ModelAttribute Contract contract, Model model) {
|
||||
model.addAttribute("contract", contractService.findByName(contract.getName()));
|
||||
return "contract/show-one";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/value-le-search
|
||||
* <p>
|
||||
* Shows form to search contract by value less equal than
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return contract/value-le-search
|
||||
*/
|
||||
@GetMapping("/value-le-search")
|
||||
public String showValueLeesThanEqualSearchForm(Model model) {
|
||||
model.addAttribute("contract", new Contract());
|
||||
return "contract/value-le-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/value-le-search
|
||||
* <p>
|
||||
* Processes request searching by value less equal than
|
||||
*
|
||||
* @param contract variable type Contract
|
||||
* @param model model to add attributes to
|
||||
* @return contract/show-list
|
||||
*/
|
||||
@PostMapping("/value-le-search")
|
||||
public String processRequestValueLessThanEqualSearch(@ModelAttribute Contract contract, Model model) {
|
||||
model.addAttribute("contracts", contractService.findAllByValueLessThanEqual(contract.getValue()));
|
||||
return "contract/show-list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/value-ge-search
|
||||
* <p>
|
||||
* Shows form to search contract by value greater equal than
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return contract/value-ge-search
|
||||
*/
|
||||
@GetMapping("/value-ge-search")
|
||||
public String showValueGreaterThanEqualSearchForm(Model model) {
|
||||
model.addAttribute("contract", new Contract());
|
||||
return "contract/value-ge-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/value-ge-search
|
||||
* <p>
|
||||
* Processes request searching by value greater equal than
|
||||
*
|
||||
* @param contract variable type Contract
|
||||
* @param model model to add attributes to
|
||||
* @return contract/show-list
|
||||
*/
|
||||
@PostMapping("/value-ge-search")
|
||||
public String processRequestValueGreaterThanEqualSearch(@ModelAttribute Contract contract, Model model) {
|
||||
model.addAttribute("contracts", contractService.findAllByValueGreaterThanEqual(contract.getValue()));
|
||||
return "contract/show-list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/begin-date-search
|
||||
* <p>
|
||||
* Shows form to search contract by begin date
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return contract/begin-date-search
|
||||
*/
|
||||
@GetMapping("/begin-date-search")
|
||||
public String showBeginDateSearchForm(Model model) {
|
||||
model.addAttribute("contract", new Contract());
|
||||
return "contract/begin-date-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/begin-date-search
|
||||
* <p>
|
||||
* Processes request searching by begin date
|
||||
*
|
||||
* @param contract variable type Contract
|
||||
* @param model model to add attributes to
|
||||
* @return contract/show-list
|
||||
*/
|
||||
@PostMapping("/begin-date-search")
|
||||
public String processRequestBeginDateSearch(@ModelAttribute Contract contract, Model model) {
|
||||
model.addAttribute("contracts", contractService.findAllByBeginDate(contract.getBeginDate()));
|
||||
return "contract/show-list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/begin-date-before-search
|
||||
* <p>
|
||||
* Shows form to search contract by begin date before
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return contract/begin-date-before-search
|
||||
*/
|
||||
@GetMapping("/begin-date-before-search")
|
||||
public String showBeginDateBeforeSearchForm(Model model) {
|
||||
model.addAttribute("contract", new Contract());
|
||||
return "contract/begin-date-before-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/begin-date-before-search
|
||||
* <p>
|
||||
* Processes request searching by begin date before
|
||||
*
|
||||
* @param contract variable type Contract
|
||||
* @param model model to add attributes to
|
||||
* @return contract/show-list
|
||||
*/
|
||||
@PostMapping("/begin-date-before-search")
|
||||
public String processRequestBeginDateBeforeSearch(@ModelAttribute Contract contract, Model model) {
|
||||
model.addAttribute("contracts", contractService.findAllByBeginDateBefore(contract.getBeginDate()));
|
||||
return "contract/show-list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/begin-date-after-search
|
||||
* <p>
|
||||
* Shows form to search contract by begin date after
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return contract/begin-date-after-search
|
||||
*/
|
||||
@GetMapping("/begin-date-after-search")
|
||||
public String showBeginDateAfterSearchForm(Model model) {
|
||||
model.addAttribute("contract", new Contract());
|
||||
return "contract/begin-date-after-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/begin-date-after-search
|
||||
* <p>
|
||||
* Processes request searching by begin date after
|
||||
*
|
||||
* @param contract variable type Contract
|
||||
* @param model model to add attributes to
|
||||
* @return contract/show-list
|
||||
*/
|
||||
@PostMapping("/begin-date-after-search")
|
||||
public String processRequestBeginDateAfterSearch(@ModelAttribute Contract contract, Model model) {
|
||||
model.addAttribute("contracts", contractService.findAllByBeginDateAfter(contract.getBeginDate()));
|
||||
return "contract/show-list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/end-date-search
|
||||
* <p>
|
||||
* Shows form to search contract by end date
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return contract/end-date-search
|
||||
*/
|
||||
@GetMapping("/end-date-search")
|
||||
public String showEndDateSearchForm(Model model) {
|
||||
model.addAttribute("contract", new Contract());
|
||||
return "contract/end-date-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/end-date-search
|
||||
* <p>
|
||||
* Processes request searching by end date
|
||||
*
|
||||
* @param contract variable type Contract
|
||||
* @param model model to add attributes to
|
||||
* @return contract/show-list
|
||||
*/
|
||||
@PostMapping("/end-date-search")
|
||||
public String processRequestEndDateSearch(@ModelAttribute Contract contract, Model model) {
|
||||
model.addAttribute("contracts", contractService.findAllByEndDate(contract.getEndDate()));
|
||||
return "contract/show-list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/end-date-before-search
|
||||
* <p>
|
||||
* Shows form to search contract by end date before
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return contract/end-date-before-search
|
||||
*/
|
||||
@GetMapping("/end-date-before-search")
|
||||
public String showEndDateBeforeSearchForm(Model model) {
|
||||
model.addAttribute("contract", new Contract());
|
||||
return "contract/end-date-before-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/end-date-before-search
|
||||
* <p>
|
||||
* Processes request searching by end date before
|
||||
*
|
||||
* @param contract variable type Contract
|
||||
* @param model model to add attributes to
|
||||
* @return contract/show-list
|
||||
*/
|
||||
@PostMapping("/end-date-before-search")
|
||||
public String processRequestEndDateBeforeSearch(@ModelAttribute Contract contract, Model model) {
|
||||
model.addAttribute("contracts", contractService.findAllByEndDateBefore(contract.getEndDate()));
|
||||
return "contract/show-list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/end-date-after-search
|
||||
* <p>
|
||||
* Shows form to search contract by end date after
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return contract/end-date-after-search
|
||||
*/
|
||||
@GetMapping("/end-date-after-search")
|
||||
public String showEndDateAfterSearchForm(Model model) {
|
||||
model.addAttribute("contract", new Contract());
|
||||
return "contract/end-date-after-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/end-date-after-search
|
||||
* <p>
|
||||
* Processes request searching by end date after
|
||||
*
|
||||
* @param contract variable type Contract
|
||||
* @param model model to add attributes to
|
||||
* @return contract/show-list
|
||||
*/
|
||||
@PostMapping("/end-date-after-search")
|
||||
public String processRequestEndDateAfterSearch(@ModelAttribute Contract contract, Model model) {
|
||||
model.addAttribute("contracts", contractService.findAllByEndDateAfter(contract.getEndDate()));
|
||||
return "contract/show-list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/status-search
|
||||
* <p>
|
||||
* Shows form to search contract by status
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return contract/status-search
|
||||
*/
|
||||
@GetMapping("/status-search")
|
||||
public String showStatusSearchForm(Model model) {
|
||||
model.addAttribute("contract", new Contract());
|
||||
return "contract/status-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/status-search
|
||||
* <p>
|
||||
* Processes request searching by status
|
||||
*
|
||||
* @param contract variable type Contract
|
||||
* @param model model to add attributes to
|
||||
* @return contract/show-list
|
||||
*/
|
||||
@PostMapping("/status-search")
|
||||
public String processRequestStatusSearch(@ModelAttribute Contract contract, Model model) {
|
||||
model.addAttribute("contracts", contractService.findAllByStatus(contract.getStatus()));
|
||||
return "contract/show-list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/customer-search
|
||||
* <p>
|
||||
* Shows form to search contract by customer
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return contract/customer-search
|
||||
*/
|
||||
@GetMapping("/customer-search")
|
||||
public String showCustomerSearchForm(Model model) {
|
||||
Iterable<Customer> customers = customerService.findAllByEnabledTrue();
|
||||
model.addAttribute("contract", new Contract());
|
||||
model.addAttribute("customers", customers);
|
||||
return "contract/customer-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/customer-search
|
||||
* <p>
|
||||
* Processes request searching by customer
|
||||
*
|
||||
* @param contract variable type Contract
|
||||
* @param model model to add attributes to
|
||||
* @return contract/show-list
|
||||
*/
|
||||
@PostMapping("/customer-search")
|
||||
public String processRequestCustomerSearch(@ModelAttribute Contract contract, Model model) {
|
||||
model.addAttribute("contracts", contractService.findAllByCustomer(contract.getCustomer()));
|
||||
return "contract/show-list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/customer-user-search
|
||||
* <p>
|
||||
* Shows form to search contract by customer and user
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return contract/customer-user-search
|
||||
*/
|
||||
@GetMapping("/customer-user-search")
|
||||
public String showCustomerUserSearchForm(Model model) {
|
||||
Iterable<Customer> customers = customerService.findAllByEnabledTrue();
|
||||
Iterable<User> users = userService.listAllUsers();
|
||||
model.addAttribute("contract", new Contract());
|
||||
model.addAttribute("customers", customers);
|
||||
model.addAttribute("users", users);
|
||||
return "contract/customer-user-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/customer-user-search
|
||||
* <p>
|
||||
* Processes request searching by customer and user
|
||||
*
|
||||
* @param contract variable type Contract
|
||||
* @param model model to add attributes to
|
||||
* @return contract/show-list
|
||||
*/
|
||||
@PostMapping("/customer-user-search")
|
||||
public String processRequestCustomerUserSearch(@ModelAttribute Contract contract, Model model) {
|
||||
model.addAttribute("contracts", contractService.findAllByCustomerAndUser(contract.getCustomer(), contract.getUser()));
|
||||
return "contract/show-list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/user-search
|
||||
* <p>
|
||||
* Shows form to search contract by user
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return contract/user-search
|
||||
*/
|
||||
@GetMapping("/user-search")
|
||||
public String showUserSearchForm(Model model) {
|
||||
Iterable<User> users = userService.listAllUsers();
|
||||
model.addAttribute("contract", new Contract());
|
||||
model.addAttribute("users", users);
|
||||
return "contract/user-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /contract/user-search
|
||||
* <p>
|
||||
* Processes request searching by user
|
||||
*
|
||||
* @param contract variable type Contract
|
||||
* @param model model to add attributes to
|
||||
* @return contract/show-list
|
||||
*/
|
||||
@PostMapping("/user-search")
|
||||
public String processRequestUserSearch(@ModelAttribute Contract contract, Model model) {
|
||||
model.addAttribute("contracts", contractService.findAllByUser(contract.getUser()));
|
||||
return "contract/show-list";
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,386 +0,0 @@
|
||||
package crm.controller;
|
||||
|
||||
import crm.entity.Customer;
|
||||
import crm.service.CustomerService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/customer")
|
||||
public class CustomerController {
|
||||
|
||||
private CustomerService customerService;
|
||||
|
||||
public CustomerController(CustomerService customerService) {
|
||||
this.customerService = customerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/list
|
||||
* <p>
|
||||
* Shows all customers
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return customer/list
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public String showAllCustomers(Model model) {
|
||||
model.addAttribute("customers", customerService.listAllCustomers());
|
||||
return "customer/list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/add
|
||||
* <p>
|
||||
* Shows add customer form
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return customer/add
|
||||
*/
|
||||
@GetMapping("/add")
|
||||
public String showFormAddCustomer(Model model) {
|
||||
model.addAttribute("customer", new Customer());
|
||||
return "customer/add";
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/add
|
||||
* <p>
|
||||
* Processes add customer request
|
||||
*
|
||||
* @param customer variable type Customer
|
||||
* @param bindingResult variable type BindingResult
|
||||
* @return customer/success
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public String processRequestAddCustomer(@Valid Customer customer, BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
return "redirect:/customer/add";
|
||||
} else {
|
||||
customerService.saveCustomer(customer);
|
||||
return "customer/success";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/edit/{id}
|
||||
* <p>
|
||||
* Shows edit customer form
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @param id variable type long customer id
|
||||
* @return customer/edit
|
||||
*/
|
||||
@GetMapping("/edit/{id}")
|
||||
public String showFormEditCustomer(Model model, @PathVariable Long id) {
|
||||
model.addAttribute("customer", customerService.showCustomer(id));
|
||||
return "customer/edit";
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/edit/{id}
|
||||
* <p>
|
||||
* Processes edit customer request
|
||||
*
|
||||
* @param id variable type long customer id
|
||||
* @param customer variable type Customer
|
||||
* @param bindingResult variable type BindingResult
|
||||
* @return redirect:/customer/list
|
||||
*/
|
||||
@PostMapping("/edit/{id}")
|
||||
public String processRequestEditCustomer(@PathVariable Long id, @Valid Customer customer,
|
||||
BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
return "redirect:/customer/edit/" + id;
|
||||
} else {
|
||||
customerService.saveCustomer(customer);
|
||||
return "redirect:/customer/list";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/addCustomerBasedOnAnotherOne/{id}
|
||||
* <p>
|
||||
* Shows create-customer-based-on-another-one form
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @param id variable type long reference customer id
|
||||
* @return customer/add-customer-based-on-another-one
|
||||
*/
|
||||
@GetMapping("/addCustomerBasedOnAnotherOne/{id}")
|
||||
public String showFormCreateCustomerBasedOnAnotherOne(Model model, @PathVariable Long id) {
|
||||
model.addAttribute("customer", customerService.showCustomer(id));
|
||||
return "customer/add-customer-based-on-another-one";
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/addCustomerBasedOnAnotherOne/{id}
|
||||
* <p>
|
||||
* Creates customer based on another one
|
||||
*
|
||||
* @param id variable type long reference customer id
|
||||
* @param customer variable type Customer
|
||||
* @param bindingResult variable type BindingResult
|
||||
* @return redirect:/customer/list
|
||||
*/
|
||||
@PostMapping("/addCustomerBasedOnAnotherOne/{id}")
|
||||
public String createCustomerBasedOnAnotherOne(@PathVariable Long id, @Valid Customer customer,
|
||||
BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
return "redirect:/customer/addCustomerBasedOnAnotherOne/" + id;
|
||||
} else {
|
||||
Customer newCustomer = new Customer(
|
||||
customerService.getMaxId() + 1L,
|
||||
customer.getName(),
|
||||
customer.getEmail(),
|
||||
customer.getPhone(),
|
||||
customer.getCategories(),
|
||||
customer.getFirstName(),
|
||||
customer.getLastName(),
|
||||
customer.getCity(),
|
||||
customer.getAddress(),
|
||||
customer.getEnabled());
|
||||
customerService.saveCustomer(newCustomer);
|
||||
return "redirect:/customer/list";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/name-search
|
||||
* <p>
|
||||
* Shows form to search customer by name
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return customer/name-search
|
||||
*/
|
||||
@GetMapping("/name-search")
|
||||
public String showNameSearchForm(Model model) {
|
||||
model.addAttribute("customer", new Customer());
|
||||
return "customer/name-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/name-search
|
||||
* <p>
|
||||
* Processes request searching by name
|
||||
*
|
||||
* @param customer variable type Customer
|
||||
* @param model model to add attributes to
|
||||
* @return customer/show-one
|
||||
*/
|
||||
@PostMapping("/name-search")
|
||||
public String processRequestNameSearch(@ModelAttribute Customer customer, Model model) {
|
||||
model.addAttribute("customer", customerService.findOneByEnabledTrueAndName(customer.getName()));
|
||||
return "customer/show-one";
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/email-search
|
||||
* <p>
|
||||
* Shows form to search customer by email
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return customer/email-search
|
||||
*/
|
||||
@GetMapping("/email-search")
|
||||
public String showEmailSearchForm(Model model) {
|
||||
model.addAttribute("customer", new Customer());
|
||||
return "customer/email-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/email-search
|
||||
* <p>
|
||||
* Processes request searching by city
|
||||
*
|
||||
* @param customer variable type Customer
|
||||
* @param model model to add attributes to
|
||||
* @return customer/show-list
|
||||
*/
|
||||
@PostMapping("/email-search")
|
||||
public String processRequestEmailSearch(@ModelAttribute Customer customer, Model model) {
|
||||
model.addAttribute("customers", customerService.findByEnabledTrueAndEmail(customer.getEmail()));
|
||||
return "customer/show-list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/phone-search
|
||||
* <p>
|
||||
* Shows form to search customer by phone
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return customer/phone-search
|
||||
*/
|
||||
@GetMapping("/phone-search")
|
||||
public String showPhoneSearchForm(Model model) {
|
||||
model.addAttribute("customer", new Customer());
|
||||
return "customer/phone-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/phone-search
|
||||
* <p>
|
||||
* Processes request searching by phone
|
||||
*
|
||||
* @param customer variable type Customer
|
||||
* @param model model to add attributes to
|
||||
* @return customer/show-list
|
||||
*/
|
||||
@PostMapping("/phone-search")
|
||||
public String processRequestPhoneSearch(@ModelAttribute Customer customer, Model model) {
|
||||
model.addAttribute("customers", customerService.findByEnabledTrueAndPhone(customer.getPhone()));
|
||||
return "customer/show-list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/first-name-search
|
||||
* <p>
|
||||
* Shows form to search customer by first name
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return customer/first-name-search
|
||||
*/
|
||||
@GetMapping("/first-name-search")
|
||||
public String showFirstNameSearchForm(Model model) {
|
||||
model.addAttribute("customer", new Customer());
|
||||
return "customer/first-name-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/first-name-search
|
||||
* <p>
|
||||
* Processes request searching by first name
|
||||
*
|
||||
* @param customer variable type Customer
|
||||
* @param model model to add attributes to
|
||||
* @return customer/show-list
|
||||
*/
|
||||
@PostMapping("/first-name-search")
|
||||
public String processRequestFirstNameSearch(@ModelAttribute Customer customer, Model model) {
|
||||
model.addAttribute("customers", customerService.findByEnabledTrueAndFirstName(customer.getFirstName()));
|
||||
return "customer/show-list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/last-name-search
|
||||
* <p>
|
||||
* Shows form to search customer by last name
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return customer/last-name-search
|
||||
*/
|
||||
@GetMapping("/last-name-search")
|
||||
public String showLastNameSearchForm(Model model) {
|
||||
model.addAttribute("customer", new Customer());
|
||||
return "customer/last-name-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/last-name-search
|
||||
* <p>
|
||||
* Processes request searching by last name
|
||||
*
|
||||
* @param customer variable type Customer
|
||||
* @param model model to add attributes to
|
||||
* @return customer/show-list
|
||||
*/
|
||||
@PostMapping("/last-name-search")
|
||||
public String processRequestLastNameSearch(@ModelAttribute Customer customer, Model model) {
|
||||
model.addAttribute("customers", customerService.findByEnabledTrueAndLastName(customer.getLastName()));
|
||||
return "customer/show-list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/first-name-last-name-search
|
||||
* <p>
|
||||
* Shows form to search customer by first name and last name
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return customer/first-name-last-name-search
|
||||
*/
|
||||
@GetMapping("/first-name-last-name-search")
|
||||
public String showFirstNameLastNameSearchForm(Model model) {
|
||||
model.addAttribute("customer", new Customer());
|
||||
return "customer/first-name-last-name-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/first-name-last-name-search
|
||||
* <p>
|
||||
* Processes request searching by first name and last name
|
||||
*
|
||||
* @param customer variable type Customer
|
||||
* @param model model to add attributes to
|
||||
* @return customer/show-list
|
||||
*/
|
||||
@PostMapping("/first-name-last-name-search")
|
||||
public String processRequestFirstNameLastNameSearch(@ModelAttribute Customer customer, Model model) {
|
||||
model.addAttribute("customers",
|
||||
customerService.findByEnabledTrueAndFirstNameAndLastName(customer.getFirstName(), customer.getLastName()));
|
||||
return "customer/show-list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/city-search
|
||||
* <p>
|
||||
* Shows form to search customer by city
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return customer/city-search
|
||||
*/
|
||||
@GetMapping("/city-search")
|
||||
public String showCitySearchForm(Model model) {
|
||||
model.addAttribute("customer", new Customer());
|
||||
return "customer/city-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/city-search
|
||||
* <p>
|
||||
* Processes request searching by city
|
||||
*
|
||||
* @param customer variable type Customer
|
||||
* @param model model to add attributes to
|
||||
* @return customer/show-list
|
||||
*/
|
||||
@PostMapping("/city-search")
|
||||
public String processRequestCitySearch(@ModelAttribute Customer customer, Model model) {
|
||||
model.addAttribute("customers", customerService.findByEnabledTrueAndCity(customer.getCity()));
|
||||
return "customer/show-list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/city-address-search
|
||||
* <p>
|
||||
* Shows form to search customer by city and address
|
||||
*
|
||||
* @param model model to add attributes to
|
||||
* @return customer/city-address-search
|
||||
*/
|
||||
@GetMapping("/city-address-search")
|
||||
public String showCityAddressSearchForm(Model model) {
|
||||
model.addAttribute("customer", new Customer());
|
||||
return "customer/city-address-search";
|
||||
}
|
||||
|
||||
/**
|
||||
* /customer/city-address-search
|
||||
* <p>
|
||||
* Processes request searching by city and address
|
||||
*
|
||||
* @param customer variable type Customer
|
||||
* @param model model to add attributes to
|
||||
* @return customer/show-list
|
||||
*/
|
||||
@PostMapping("/city-address-search")
|
||||
public String processRequestCityAddressSearch(@ModelAttribute Customer customer, Model model) {
|
||||
model.addAttribute("customers",
|
||||
customerService.findByEnabledTrueAndCityAndAddress(customer.getCity(), customer.getAddress()));
|
||||
return "customer/show-list";
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
package crm.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/date")
|
||||
public class DateTimeTestController {
|
||||
|
||||
@GetMapping("/test")
|
||||
public String dateTimeTest(Model model) {
|
||||
model.addAttribute("standardDate", new Date());
|
||||
model.addAttribute("localDateTime", LocalDateTime.now());
|
||||
model.addAttribute("localDate", LocalDate.now());
|
||||
model.addAttribute("timestamp", Instant.now());
|
||||
return "date/test";
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,26 +0,0 @@
|
||||
package crm.controller;
|
||||
|
||||
import crm.service.UserService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
public class Export {
|
||||
|
||||
private UserService userService;
|
||||
|
||||
public Export(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle request to download an Excel document
|
||||
*/
|
||||
@GetMapping("/download")
|
||||
public String download(Model model) {
|
||||
model.addAttribute("users", userService.listAllUsers());
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
package crm.controller;
|
||||
|
||||
//@Controller
|
||||
public class ExportCustomers {
|
||||
|
||||
// @Autowired
|
||||
// CustomerService customerService;
|
||||
//
|
||||
// /**
|
||||
// * Handle request to download an Excel document
|
||||
// */
|
||||
// @GetMapping("/download")
|
||||
// public String download(Model model) {
|
||||
// model.addAttribute("customers", customerService.listAllCustomers());
|
||||
// return "";
|
||||
// }
|
||||
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
package crm.controller;
|
||||
|
||||
import org.springframework.boot.autoconfigure.web.ErrorController;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class MyErrorController implements ErrorController {
|
||||
|
||||
private static final String PATH = "/error";
|
||||
|
||||
@RequestMapping(value = PATH)
|
||||
public String error() {
|
||||
return "Error handling";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorPath() {
|
||||
return PATH;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,65 +0,0 @@
|
||||
package crm.controller;
|
||||
|
||||
import com.itextpdf.text.Document;
|
||||
import com.itextpdf.text.DocumentException;
|
||||
import com.itextpdf.text.Paragraph;
|
||||
import com.itextpdf.text.pdf.PdfWriter;
|
||||
import crm.entity.Pdf;
|
||||
import crm.service.PdfService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
@Controller
|
||||
@Slf4j
|
||||
public class PdfController {
|
||||
|
||||
private PdfService pdfService;
|
||||
|
||||
public PdfController(PdfService pdfService) {
|
||||
this.pdfService = pdfService;
|
||||
}
|
||||
|
||||
private void generateSamplePdf(String fileName, String text) throws FileNotFoundException, DocumentException {
|
||||
if (!fileName.endsWith(".pdf")) {
|
||||
fileName += ".pdf";
|
||||
}
|
||||
Document document = new Document();
|
||||
PdfWriter.getInstance(document, new FileOutputStream(fileName));
|
||||
document.open();
|
||||
Paragraph paragraph = new Paragraph(text);
|
||||
document.add(paragraph);
|
||||
document.close();
|
||||
}
|
||||
|
||||
@GetMapping("/pdf-generator")
|
||||
public String pdfGenerator(Model model) {
|
||||
model.addAttribute("pdf", new Pdf());
|
||||
return "pdf/generator";
|
||||
}
|
||||
|
||||
@PostMapping("/pdf-generator")
|
||||
public String generatePdf(@Valid Pdf pdf, BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
return "redirect:/pdf-generator";
|
||||
} else {
|
||||
try {
|
||||
generateSamplePdf(pdf.getName(), pdf.getContent());
|
||||
pdfService.savePdf(pdf);
|
||||
} catch (FileNotFoundException e) {
|
||||
log.info("File Not Found");
|
||||
} catch (DocumentException e) {
|
||||
log.info("Document");
|
||||
}
|
||||
return "pdf/success";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
package crm.controller;
|
||||
|
||||
import crm.entity.User;
|
||||
import crm.service.UserService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
public class RegisterController {
|
||||
|
||||
private UserService userService;
|
||||
|
||||
public RegisterController(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@GetMapping("/register")
|
||||
public String showRegistrationPage(Model model, User user){
|
||||
model.addAttribute("user", user);
|
||||
return "register";
|
||||
}
|
||||
|
||||
@PostMapping("/register")
|
||||
public String processRegistrationForm(Model model, @Valid User user, BindingResult bindingResult) {
|
||||
User userFromDB = userService.findByUsername(user.getUsername());
|
||||
|
||||
if (userFromDB != null) {
|
||||
model.addAttribute("alreadyRegisteredMessage",
|
||||
"Oops! There is already a user registered with the email provided.");
|
||||
bindingResult.reject("email");
|
||||
return "register";
|
||||
}
|
||||
|
||||
if (bindingResult.hasErrors()) {
|
||||
return "redirect:/register";
|
||||
} else {
|
||||
userService.saveUser(user);
|
||||
return "success";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,92 +0,0 @@
|
||||
package crm.controller;
|
||||
|
||||
import crm.entity.User;
|
||||
import crm.service.UserService;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
|
||||
private UserService userService;
|
||||
|
||||
public UserController(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* /user/list
|
||||
* <p>
|
||||
* Shows all users
|
||||
*
|
||||
* @param model model to attributes to
|
||||
* @return user/list
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public String showAllUsers(Model model, @AuthenticationPrincipal UserDetails currentUser) {
|
||||
model.addAttribute("currentUser", userService.findByUsername(currentUser.getUsername()));
|
||||
model.addAttribute("users", userService.listAllUsers());
|
||||
return "user/list";
|
||||
}
|
||||
|
||||
/**
|
||||
* /user/edit/{id}
|
||||
* <p>
|
||||
* Shows edit user form
|
||||
*
|
||||
* @param model model to attributes to
|
||||
* @param id variable type long user id
|
||||
* @return user/edit
|
||||
*/
|
||||
@GetMapping("/edit/{id}")
|
||||
public String showFormEditUser(Model model, @PathVariable Long id) {
|
||||
model.addAttribute("user", userService.showUser(id));
|
||||
return "user/edit";
|
||||
}
|
||||
|
||||
/**
|
||||
* /user/edit/{id}
|
||||
* <p>
|
||||
* Processes edit user request
|
||||
*
|
||||
* @param id variable type long user id
|
||||
* @param user variable type User
|
||||
* @param bindingResult variable type BindingResult
|
||||
* @return redirect:/user/list
|
||||
*/
|
||||
@PostMapping("/edit/{id}")
|
||||
public String processRequestEditUser(@PathVariable Long id, @Valid User user,
|
||||
BindingResult bindingResult) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
return "redirect:/user/edit/" + id;
|
||||
} else {
|
||||
userService.editUser(user);
|
||||
return "redirect:/user/list";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* /user/delete/{id}
|
||||
* <p>
|
||||
* Deletes user
|
||||
*
|
||||
* @param id variable type long user id
|
||||
* @return redirect:/user/list
|
||||
*/
|
||||
@GetMapping("/delete/{id}")
|
||||
public String deleteUser(@PathVariable Long id) {
|
||||
userService.deleteUser(userService.showUser(id));
|
||||
return "redirect:/user/list";
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
package crm.csv;
|
||||
|
||||
import com.opencsv.CSVReader;
|
||||
import crm.utils.ReadDataUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CSVTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
File document = ReadDataUtils.ReadFile("Select CSV file", null, "Only CSV Files", "csv");
|
||||
// System.out.println(document.getName());
|
||||
|
||||
CSVReader reader;
|
||||
List<Object[]> data = new ArrayList<>();
|
||||
try {
|
||||
reader = new CSVReader(new FileReader(document));
|
||||
String[] line;
|
||||
while ((line = reader.readNext()) != null) {
|
||||
// System.out.println(line[1] + "\t" + line[2]);
|
||||
data.add(line);
|
||||
if(line[1].equals("QUICK SUB")){
|
||||
System.out.println(line[0] + "\t" + line[1] + "\t" + line[2]);
|
||||
}
|
||||
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
/*System.out.println(data.get(0)[1] + "\t" + data.get(0)[2]);
|
||||
System.out.println(data.get(1)[1] + "\t" + data.get(1)[2]);*/
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
package crm.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name = "category")
|
||||
public class Category {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@Column(name = "category_id")
|
||||
private Long id;
|
||||
|
||||
@Column(name = "category")
|
||||
private String name;
|
||||
|
||||
}
|
||||
@ -1,49 +0,0 @@
|
||||
package crm.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Contract {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false, unique = true)
|
||||
private String name;
|
||||
|
||||
private String content;
|
||||
|
||||
private BigDecimal value;
|
||||
|
||||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
|
||||
private LocalDate beginDate;
|
||||
|
||||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
|
||||
private LocalDate endDate;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Status status;
|
||||
|
||||
@ManyToOne
|
||||
private Customer customer;
|
||||
|
||||
@ManyToOne
|
||||
private User user;
|
||||
|
||||
// @Transient
|
||||
// private DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
|
||||
|
||||
}
|
||||
@ -1,52 +0,0 @@
|
||||
package crm.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
public class CurrentUser implements UserDetails {
|
||||
|
||||
private User user;
|
||||
|
||||
private Set<GrantedAuthority> authorities;
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
return authorities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return user.getPassword();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return user.getUsername();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,54 +0,0 @@
|
||||
package crm.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.hibernate.validator.constraints.Email;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.Digits;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.Set;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Customer {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false, unique = true)
|
||||
@Size(min = 2)
|
||||
private String name;
|
||||
|
||||
@Column(name = "email", nullable = false, unique = true)
|
||||
@Email(message = "Please provide a valid e-mail")
|
||||
@NotEmpty(message = "Please provide an e-mail")
|
||||
private String email;
|
||||
|
||||
@Digits(fraction = 0, integer = 20)
|
||||
private int phone;
|
||||
|
||||
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
@JoinTable(name = "customer_category",
|
||||
joinColumns = @JoinColumn(name = "customer_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "category_id"))
|
||||
private Set<Category> categories;
|
||||
|
||||
private String firstName;
|
||||
|
||||
private String lastName;
|
||||
|
||||
private String city;
|
||||
|
||||
private String address;
|
||||
|
||||
private int enabled;
|
||||
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
package crm.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
@Entity(name = "pdf")
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Pdf {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
@Size(min = 2)
|
||||
private String name;
|
||||
|
||||
@Transient
|
||||
private String content;
|
||||
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
package crm.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name = "role")
|
||||
public class Role {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@Column(name = "role_id")
|
||||
private int id;
|
||||
|
||||
@Column(name = "role", unique = true)
|
||||
private String name;
|
||||
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
package crm.entity;
|
||||
|
||||
public enum Status {
|
||||
|
||||
PROPOSED,
|
||||
NEGOTIATED,
|
||||
IMPLEMENTED,
|
||||
DONE;
|
||||
|
||||
public static final Status[] ALL = {PROPOSED, NEGOTIATED, IMPLEMENTED, DONE};
|
||||
|
||||
}
|
||||
@ -1,58 +0,0 @@
|
||||
package crm.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.hibernate.validator.constraints.Email;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity(name = "users")
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class User {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false, unique = true)
|
||||
private String username;
|
||||
|
||||
@Column(name = "email", nullable = false, unique = true)
|
||||
@Email(message = "Please provide a valid e-mail")
|
||||
@NotEmpty(message = "Please provide an e-mail")
|
||||
private String email;
|
||||
|
||||
private String firstName;
|
||||
|
||||
private String lastName;
|
||||
|
||||
private String password;
|
||||
|
||||
private int enabled;
|
||||
|
||||
@ManyToOne
|
||||
private Role role;
|
||||
|
||||
public int getColumnCount() {
|
||||
return getClass().getDeclaredFields().length;
|
||||
}
|
||||
|
||||
public int getRole_id() {
|
||||
return role.getId();
|
||||
}
|
||||
|
||||
public String getRole_name() {
|
||||
return role.getName();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return firstName + " " + lastName;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue