瀏覽代碼

Implement-cert-tb-customer-and-feature-upload-stamp

new-feature
Viet.LeQ2 1 年之前
父節點
當前提交
1e3452af22
共有 14 個文件被更改,包括 333 次插入43 次删除
  1. 二進制
      build/libs/smart-farm-0.0.1-SNAPSHOT.war
  2. +4
    -0
      src/main/java/vn/azteam/tpf/Constants/Constants.java
  3. +12
    -0
      src/main/java/vn/azteam/tpf/domain/TBCustomer.java
  4. +2
    -0
      src/main/java/vn/azteam/tpf/service/FileStorageService.java
  5. +31
    -1
      src/main/java/vn/azteam/tpf/service/TBCustomerQueryService.java
  6. +32
    -4
      src/main/java/vn/azteam/tpf/service/TBExampleStampQueryService.java
  7. +7
    -0
      src/main/java/vn/azteam/tpf/service/TBExampleStampService.java
  8. +11
    -0
      src/main/java/vn/azteam/tpf/service/dto/TBCustomerDTO.java
  9. +64
    -0
      src/main/java/vn/azteam/tpf/service/dto/TBExampleStampCreationDTO.java
  10. +5
    -0
      src/main/java/vn/azteam/tpf/service/impl/FileStorageServiceImpl.java
  11. +37
    -0
      src/main/java/vn/azteam/tpf/service/impl/TBExampleStampServiceImpl.java
  12. +68
    -31
      src/main/java/vn/azteam/tpf/web/rest/TBCustomerResource.java
  13. +58
    -7
      src/main/java/vn/azteam/tpf/web/rest/TBExampleStampResource.java
  14. +2
    -0
      src/main/resources/config/liquibase/sql/20240305_add_column_cert_image_tb_customer.sql

二進制
build/libs/smart-farm-0.0.1-SNAPSHOT.war 查看文件


+ 4
- 0
src/main/java/vn/azteam/tpf/Constants/Constants.java 查看文件



public static String ACTIVE_TYPE_END = "ACTIVE_TYPE_END"; public static String ACTIVE_TYPE_END = "ACTIVE_TYPE_END";


public static String EXAMPLE_STAMP = "EXAMPLE_STAMP";

public static String CUSTOMER_CERT = "CUSTOMER_CERT";

public static enum ENUM_MENU_ALWAYS_SHOW { public static enum ENUM_MENU_ALWAYS_SHOW {
DASHBOARD DASHBOARD
} }

+ 12
- 0
src/main/java/vn/azteam/tpf/domain/TBCustomer.java 查看文件

@Column(name = "api_key") @Column(name = "api_key")
private String apiKey; private String apiKey;


@Column(name = "certification_image")
private String certificationImage;

@ManyToOne @ManyToOne
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
private TBAddress tbAddress; private TBAddress tbAddress;
this.apiKey = apiKey; this.apiKey = apiKey;
} }



public String getCertificationImage() {
return certificationImage;
}

public void setCertificationImage(String certificationImage) {
this.certificationImage = certificationImage;
}

@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

+ 2
- 0
src/main/java/vn/azteam/tpf/service/FileStorageService.java 查看文件

*/ */
String storeFiles(String itemTimeLineId, MultipartFile[] files); String storeFiles(String itemTimeLineId, MultipartFile[] files);


String storeSingleFile(String itemTimeLineId, MultipartFile file);



/** /**
* Remove uploaded files * Remove uploaded files

+ 31
- 1
src/main/java/vn/azteam/tpf/service/TBCustomerQueryService.java 查看文件



import java.time.Instant; import java.time.Instant;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;


import javax.persistence.EntityManager; import javax.persistence.EntityManager;


import io.github.jhipster.service.QueryService; import io.github.jhipster.service.QueryService;
import io.github.jhipster.service.filter.LongFilter; import io.github.jhipster.service.filter.LongFilter;
import org.springframework.web.multipart.MultipartFile;
import vn.azteam.tpf.domain.TBCustomer; import vn.azteam.tpf.domain.TBCustomer;
import vn.azteam.tpf.domain.*; // for static metamodels import vn.azteam.tpf.domain.*; // for static metamodels
import vn.azteam.tpf.repository.TBCustomerRepository; import vn.azteam.tpf.repository.TBCustomerRepository;


private final TBCustomerSearchRepository tBCustomerSearchRepository; private final TBCustomerSearchRepository tBCustomerSearchRepository;


private final FileStorageService fileStorageService;

private final TBCustomerService tBCustomerService; private final TBCustomerService tBCustomerService;


private final TBAddressService tBAddressService; private final TBAddressService tBAddressService;


private final EntityManager em; private final EntityManager em;


public TBCustomerQueryService(TBCustomerRepository tBCustomerRepository, TBCustomerMapper tBCustomerMapper, TBCustomerSearchRepository tBCustomerSearchRepository, TBCustomerService tBCustomerService, TBAddressService tBAddressService, UserService userService, EntityManager em) {
public TBCustomerQueryService(TBCustomerRepository tBCustomerRepository, TBCustomerMapper tBCustomerMapper, TBCustomerSearchRepository tBCustomerSearchRepository, FileStorageService fileStorageService, TBCustomerService tBCustomerService, TBAddressService tBAddressService, UserService userService, EntityManager em) {
this.tBCustomerRepository = tBCustomerRepository; this.tBCustomerRepository = tBCustomerRepository;
this.tBCustomerMapper = tBCustomerMapper; this.tBCustomerMapper = tBCustomerMapper;
this.tBCustomerSearchRepository = tBCustomerSearchRepository; this.tBCustomerSearchRepository = tBCustomerSearchRepository;
this.fileStorageService = fileStorageService;
this.tBCustomerService = tBCustomerService; this.tBCustomerService = tBCustomerService;
this.tBAddressService = tBAddressService; this.tBAddressService = tBAddressService;
this.userService = userService; this.userService = userService;
return tBCustomerService.save(tBCustomerDTO); return tBCustomerService.save(tBCustomerDTO);
} }


@Transactional()
public TBCustomerDTO updateCustomerWithCertImage(TBCustomerDTO tBCustomerDTO,
MultipartFile file, String path){
Optional<UserDTO> currentUser = userService.getCurrentUserDTO();
String imagePath;
if (null != file) {
if (Objects.equals(file.getOriginalFilename(), "")) {
tBCustomerDTO.setCertificationImage(tBCustomerDTO.getCertificationImage());
} else {
imagePath = this.fileStorageService.storeSingleFile(path, file);
if (tBCustomerDTO.getCertificationImage() != null &&
!tBCustomerDTO.getCertificationImage().equals("")) {
tBCustomerDTO.setCertificationImage(imagePath);
} else {
tBCustomerDTO.setCertificationImage(imagePath);
}
}
} else {
tBCustomerDTO.setCertificationImage(tBCustomerDTO.getCertificationImage());
}
tBCustomerDTO.setModifiedById(currentUser.get().getId());
tBCustomerDTO.setModifiedDate(Instant.now());
return tBCustomerService.save(tBCustomerDTO);
}

@Transactional() @Transactional()
public TBCustomerDTO updateCustomer(TBCustomerDTO tBCustomerDTO){ public TBCustomerDTO updateCustomer(TBCustomerDTO tBCustomerDTO){
Optional<UserDTO> currentUser = userService.getCurrentUserDTO(); Optional<UserDTO> currentUser = userService.getCurrentUserDTO();

+ 32
- 4
src/main/java/vn/azteam/tpf/service/TBExampleStampQueryService.java 查看文件

import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import vn.azteam.tpf.domain.TBDetailUser; import vn.azteam.tpf.domain.TBDetailUser;
import vn.azteam.tpf.domain.TBDetailUser_; import vn.azteam.tpf.domain.TBDetailUser_;
import vn.azteam.tpf.domain.TBExampleStamp; import vn.azteam.tpf.domain.TBExampleStamp;


import javax.persistence.criteria.Join; import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType; import javax.persistence.criteria.JoinType;
import java.util.Objects;


@Service @Service
@Transactional(readOnly = true) @Transactional(readOnly = true)


private final TBExampleStampRepository tBExampleStampRepository; private final TBExampleStampRepository tBExampleStampRepository;


private final TBExampleStampMapper TBExampleStampMapper;
private final TBExampleStampMapper tBExampleStampMapper;


public TBExampleStampQueryService(TBExampleStampRepository tBExampleStampRepository, vn.azteam.tpf.service.mapper.TBExampleStampMapper tbExampleStampMapper) {
private final FileStorageService fileStorageService;

public TBExampleStampQueryService(TBExampleStampRepository tBExampleStampRepository,
TBExampleStampMapper tbExampleStampMapper,
FileStorageService fileStorageService) {
this.tBExampleStampRepository = tBExampleStampRepository; this.tBExampleStampRepository = tBExampleStampRepository;
TBExampleStampMapper = tbExampleStampMapper;
this.tBExampleStampMapper = tbExampleStampMapper;
this.fileStorageService = fileStorageService;
} }


@Transactional(readOnly = true) @Transactional(readOnly = true)
log.debug("find by criteria : {}, page: {}", criteria, page); log.debug("find by criteria : {}, page: {}", criteria, page);
final Specification<TBExampleStamp> specification = createSpecification(criteria); final Specification<TBExampleStamp> specification = createSpecification(criteria);
return tBExampleStampRepository.findAll(specification, page) return tBExampleStampRepository.findAll(specification, page)
.map(TBExampleStampMapper::toDto);
.map(tBExampleStampMapper::toDto);
} }




} }
return specification; return specification;
} }

@Transactional(propagation = Propagation.REQUIRES_NEW)
public TBExampleStampDTO saveUploadedFile(TBExampleStampDTO tbExampleStampDTO, MultipartFile file, String path) {
String imagePath;
if (null != file) {
if (Objects.equals(file.getOriginalFilename(), "")) {
tbExampleStampDTO.setExampleStampImage(tbExampleStampDTO.getExampleStampImage());
} else {
imagePath = this.fileStorageService.storeSingleFile(path, file);
if (tbExampleStampDTO.getExampleStampImage() != null && !tbExampleStampDTO.getExampleStampImage().equals("")) {
tbExampleStampDTO.setExampleStampImage(imagePath);
} else {
tbExampleStampDTO.setExampleStampImage(imagePath);
}
}
} else {
tbExampleStampDTO.setExampleStampImage(tbExampleStampDTO.getExampleStampImage());
}
return tbExampleStampDTO;
}
} }

+ 7
- 0
src/main/java/vn/azteam/tpf/service/TBExampleStampService.java 查看文件

package vn.azteam.tpf.service;

import vn.azteam.tpf.service.dto.TBExampleStampDTO;

public interface TBExampleStampService {
TBExampleStampDTO save(TBExampleStampDTO tBExampleStampDTO);
}

+ 11
- 0
src/main/java/vn/azteam/tpf/service/dto/TBCustomerDTO.java 查看文件



private String apiKey; private String apiKey;


private String certificationImage;

public Long getId() { public Long getId() {
return id; return id;
} }
this.apiKey = apiKey; this.apiKey = apiKey;
} }



public String getCertificationImage() {
return certificationImage;
}

public void setCertificationImage(String certificationImage) {
this.certificationImage = certificationImage;
}

@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

+ 64
- 0
src/main/java/vn/azteam/tpf/service/dto/TBExampleStampCreationDTO.java 查看文件

private Integer size; private Integer size;


private String exampleStampImage; private String exampleStampImage;

public String getExampleStampName() {
return exampleStampName;
}

public void setExampleStampName(String exampleStampName) {
this.exampleStampName = exampleStampName;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public Integer getWidth() {
return width;
}

public void setWidth(Integer width) {
this.width = width;
}

public Integer getHeight() {
return height;
}

public void setHeight(Integer height) {
this.height = height;
}

public Integer getX() {
return x;
}

public void setX(Integer x) {
this.x = x;
}

public Integer getY() {
return y;
}

public void setY(Integer y) {
this.y = y;
}

public Integer getSize() {
return size;
}

public void setSize(Integer size) {
this.size = size;
}

public String getExampleStampImage() {
return exampleStampImage;
}

public void setExampleStampImage(String exampleStampImage) {
this.exampleStampImage = exampleStampImage;
}
} }

+ 5
- 0
src/main/java/vn/azteam/tpf/service/impl/FileStorageServiceImpl.java 查看文件

.collect(Collectors.joining( ";" )); .collect(Collectors.joining( ";" ));
} }


@Override
public String storeSingleFile(String itemTimeLineId, MultipartFile file) {
return this.storeFile(itemTimeLineId, file);
}

/** /**
* Remove file * Remove file
* @param itemTimeLineId * @param itemTimeLineId

+ 37
- 0
src/main/java/vn/azteam/tpf/service/impl/TBExampleStampServiceImpl.java 查看文件

package vn.azteam.tpf.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vn.azteam.tpf.domain.TBExampleStamp;
import vn.azteam.tpf.repository.TBExampleStampRepository;
import vn.azteam.tpf.service.TBExampleStampService;
import vn.azteam.tpf.service.dto.TBExampleStampDTO;
import vn.azteam.tpf.service.mapper.TBExampleStampMapper;

@Service
@Transactional
public class TBExampleStampServiceImpl implements TBExampleStampService {

private final Logger log = LoggerFactory.getLogger(TBExampleStampServiceImpl.class);

private final TBExampleStampRepository tbExampleStampRepository;

private final TBExampleStampMapper tBExampleStampMapper;

public TBExampleStampServiceImpl(TBExampleStampRepository tbExampleStampRepository, TBExampleStampMapper tBExampleStampMapper) {
this.tbExampleStampRepository = tbExampleStampRepository;
this.tBExampleStampMapper = tBExampleStampMapper;
}

@Override
public TBExampleStampDTO save(TBExampleStampDTO tBExampleStampDTO) {
log.debug("Request to save TBExampleStampDTO : {}", tBExampleStampDTO);

TBExampleStamp tbExampleStamp = tBExampleStampMapper.toEntity(tBExampleStampDTO);

tbExampleStamp = tbExampleStampRepository.save(tbExampleStamp);
return tBExampleStampMapper.toDto(tbExampleStamp);
}
}

+ 68
- 31
src/main/java/vn/azteam/tpf/web/rest/TBCustomerResource.java 查看文件

package vn.azteam.tpf.web.rest; package vn.azteam.tpf.web.rest;


import com.codahale.metrics.annotation.Timed; import com.codahale.metrics.annotation.Timed;
import io.github.jhipster.web.util.ResponseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vn.azteam.tpf.Constants.Constants;
import vn.azteam.tpf.service.TBCustomerQueryService;
import vn.azteam.tpf.service.TBCustomerService; import vn.azteam.tpf.service.TBCustomerService;
import vn.azteam.tpf.service.TBRoleService; import vn.azteam.tpf.service.TBRoleService;
import vn.azteam.tpf.service.UserService; import vn.azteam.tpf.service.UserService;
import vn.azteam.tpf.service.dto.TBCustomerCriteria;
import vn.azteam.tpf.service.dto.TBCustomerDTO;
import vn.azteam.tpf.service.dto.TBRoleDTO; import vn.azteam.tpf.service.dto.TBRoleDTO;
import vn.azteam.tpf.service.dto.UserDTO; import vn.azteam.tpf.service.dto.UserDTO;
import vn.azteam.tpf.service.util.UserRoleUtil; import vn.azteam.tpf.service.util.UserRoleUtil;
import vn.azteam.tpf.web.rest.errors.ForbiddenException; import vn.azteam.tpf.web.rest.errors.ForbiddenException;
import vn.azteam.tpf.web.rest.util.HeaderUtil; import vn.azteam.tpf.web.rest.util.HeaderUtil;
import vn.azteam.tpf.web.rest.util.PaginationUtil; import vn.azteam.tpf.web.rest.util.PaginationUtil;
import vn.azteam.tpf.service.dto.TBCustomerDTO;
import vn.azteam.tpf.service.dto.TBCustomerCriteria;
import vn.azteam.tpf.service.TBCustomerQueryService;
import io.github.jhipster.web.util.ResponseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


import javax.servlet.http.HttpServletRequest;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;


/** /**
.headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())) .headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString()))
.body(result); .body(result);
} }
public String createApiKey(){

public String createApiKey() {
return UUID.randomUUID().toString(); return UUID.randomUUID().toString();
} }

/** /**
* PUT /tb-customers : Updates an existing tBCustomer. * PUT /tb-customers : Updates an existing tBCustomer.
* *
.body(result); .body(result);
} }


@PutMapping("/tb-customers/{customerId}/upload-cert")
@Timed
public ResponseEntity<TBCustomerDTO> updateTBCustomer(@PathVariable Long customerId,
@RequestPart("file") MultipartFile file) throws URISyntaxException {
log.debug("REST request to update TBCustomer id : {}", customerId);
if (file.isEmpty()) {
throw new BadRequestAlertException("File upload ", ENTITY_NAME, "is not null");
}
if (customerId == null) {
throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");
}
Optional<TBCustomerDTO> tbCustomerDTOOptional = tBCustomerService.findOne(customerId);
if (!tbCustomerDTOOptional.isPresent()) {
throw new BadRequestAlertException("Customer not found", ENTITY_NAME, "customernotfound");
}

UserDTO currentUser = userService.getCurrentUserDTO().get();
// if(currentUser.getCustomerId() != null && !currentUser.getCustomerId().equals(customerId)){
// throw new ForbiddenException();
// }
// if (currentUser.getCustomerId() != null) {
// throw new ForbiddenException();
// }
// String apiKeyNew = this.createApiKey();
TBCustomerDTO tbCustomerDTO = tbCustomerDTOOptional.get();
//tbCustomerDTO.setCertificationImage(apiKeyNew);
TBCustomerDTO result = tBCustomerQueryService.updateCustomerWithCertImage(tbCustomerDTO,
file, Constants.EXAMPLE_STAMP);
return ResponseEntity.ok()
.headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, tbCustomerDTO.getId().toString()))
.body(result);
}

@PutMapping("/tb-customers-api-key/{customerId}") @PutMapping("/tb-customers-api-key/{customerId}")
@Timed @Timed
public ResponseEntity<TBCustomerDTO> updateTBCustomerApiKey(@PathVariable Long customerId) { public ResponseEntity<TBCustomerDTO> updateTBCustomerApiKey(@PathVariable Long customerId) {
log.debug("REST request to update Api-Key TBCustomer"); log.debug("REST request to update Api-Key TBCustomer");
if (customerId == null){
if (customerId == null) {
throw new BadRequestAlertException("Invalid customer", ENTITY_NAME, "customeridnull"); throw new BadRequestAlertException("Invalid customer", ENTITY_NAME, "customeridnull");
} }
Optional<TBCustomerDTO> tbCustomerDTOOptional = tBCustomerService.findOne(customerId); Optional<TBCustomerDTO> tbCustomerDTOOptional = tBCustomerService.findOne(customerId);
if (!tbCustomerDTOOptional.isPresent()){
if (!tbCustomerDTOOptional.isPresent()) {
throw new BadRequestAlertException("Customer not found", ENTITY_NAME, "customernotfound"); throw new BadRequestAlertException("Customer not found", ENTITY_NAME, "customernotfound");
} }
UserDTO currentUser = userService.getCurrentUserDTO().get(); UserDTO currentUser = userService.getCurrentUserDTO().get();
// if(currentUser.getCustomerId() != null && !currentUser.getCustomerId().equals(customerId)){ // if(currentUser.getCustomerId() != null && !currentUser.getCustomerId().equals(customerId)){
// throw new ForbiddenException(); // throw new ForbiddenException();
// } // }
if (currentUser.getCustomerId() != null){
if (currentUser.getCustomerId() != null) {
throw new ForbiddenException(); throw new ForbiddenException();
} }
String apiKeyNew = this.createApiKey(); String apiKeyNew = this.createApiKey();
.headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, tbCustomerDTO.getId().toString())) .headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, tbCustomerDTO.getId().toString()))
.body(result); .body(result);
} }

/** /**
* GET /tb-customers : get all the tBCustomers. * GET /tb-customers : get all the tBCustomers.
* *
*/ */
@GetMapping("/tb-customers-dropdown-list/{roleId}") @GetMapping("/tb-customers-dropdown-list/{roleId}")
@Timed @Timed
public ResponseEntity<List<TBCustomerDTO>> getAllTBCustomersByRoleId(@PathVariable Long roleId,TBCustomerCriteria criteria, Pageable pageable) {
public ResponseEntity<List<TBCustomerDTO>> getAllTBCustomersByRoleId(@PathVariable Long roleId, TBCustomerCriteria criteria, Pageable pageable) {
log.debug("REST request to get TBCustomers by criteria: {}", criteria); log.debug("REST request to get TBCustomers by criteria: {}", criteria);
UserDTO currentUser = userService.getCurrentUserDTO().get(); UserDTO currentUser = userService.getCurrentUserDTO().get();
TBRoleDTO roleDTO = tbRoleService.findOne(roleId).get(); TBRoleDTO roleDTO = tbRoleService.findOne(roleId).get();


Page<TBCustomerDTO> page = tBCustomerQueryService.findByCriteria(criteria, pageable); Page<TBCustomerDTO> page = tBCustomerQueryService.findByCriteria(criteria, pageable);
List<TBCustomerDTO> result = page.getContent(); List<TBCustomerDTO> result = page.getContent();
if(currentUser.getCustomerId() != null){
if (currentUser.getCustomerId() != null) {
result = page.getContent().stream() result = page.getContent().stream()
.filter(item -> item.getId().equals(currentUser.getCustomerId())) .filter(item -> item.getId().equals(currentUser.getCustomerId()))
.collect(Collectors.toList());
.collect(Collectors.toList());
} else { } else {
if (!roleDTO.getIsAllCustomer()) { if (!roleDTO.getIsAllCustomer()) {
result = page.getContent().stream() result = page.getContent().stream()
} }


/** /**
* GET /tb-customers/count : count all the tBCustomers.
*
* @param criteria the criterias which the requested entities should match
* @return the ResponseEntity with status 200 (OK) and the count in body
*/
* GET /tb-customers/count : count all the tBCustomers.
*
* @param criteria the criterias which the requested entities should match
* @return the ResponseEntity with status 200 (OK) and the count in body
*/
@GetMapping("/tb-customers/count") @GetMapping("/tb-customers/count")
@Timed @Timed
public ResponseEntity<Long> countTBCustomers(TBCustomerCriteria criteria) { public ResponseEntity<Long> countTBCustomers(TBCustomerCriteria criteria) {
public ResponseEntity<TBCustomerDTO> getTBCustomerByCurrentUser() { public ResponseEntity<TBCustomerDTO> getTBCustomerByCurrentUser() {


UserDTO currentUser = userService.getCurrentUserDTO().get(); UserDTO currentUser = userService.getCurrentUserDTO().get();
if(currentUser.getCustomerId() != null) {
if (currentUser.getCustomerId() != null) {
Optional<TBCustomerDTO> tBCustomerDTO = tBCustomerService.findOne(currentUser.getCustomerId()); Optional<TBCustomerDTO> tBCustomerDTO = tBCustomerService.findOne(currentUser.getCustomerId());
return ResponseUtil.wrapOrNotFound(tBCustomerDTO); return ResponseUtil.wrapOrNotFound(tBCustomerDTO);
} }
* SEARCH /_search/tb-customers?query=:query : search for the tBCustomer corresponding * SEARCH /_search/tb-customers?query=:query : search for the tBCustomer corresponding
* to the query. * to the query.
* *
* @param query the query of the tBCustomer search
* @param query the query of the tBCustomer search
* @param pageable the pagination information * @param pageable the pagination information
* @return the result of the search * @return the result of the search
*/ */
@GetMapping("/_search/tb-customers") @GetMapping("/_search/tb-customers")
@Timed @Timed
public ResponseEntity<List<TBCustomerDTO>> searchTBCustomers(@RequestParam String query, @RequestParam String status, Pageable pageable) {
public ResponseEntity<List<TBCustomerDTO>> searchTBCustomers(@RequestParam String query, @RequestParam String status, Pageable pageable) {
log.debug("REST request to search for a page of TBCustomers for query {}", query); log.debug("REST request to search for a page of TBCustomers for query {}", query);
UserDTO currentUser = userService.getCurrentUserDTO().get(); UserDTO currentUser = userService.getCurrentUserDTO().get();
if (currentUser.getCustomerId() != null) { if (currentUser.getCustomerId() != null) {
Page<TBCustomerDTO> page; Page<TBCustomerDTO> page;
if((query != null && !query.isEmpty()) | (status != null && !status.isEmpty())) {
if ((query != null && !query.isEmpty()) | (status != null && !status.isEmpty())) {
page = tBCustomerQueryService.searchCustomer(query, status, pageable); page = tBCustomerQueryService.searchCustomer(query, status, pageable);
} else { } else {
page = tBCustomerService.search(query, pageable); page = tBCustomerService.search(query, pageable);

+ 58
- 7
src/main/java/vn/azteam/tpf/web/rest/TBExampleStampResource.java 查看文件





import com.codahale.metrics.annotation.Timed; import com.codahale.metrics.annotation.Timed;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import vn.azteam.tpf.domain.TBCodeStatusEnum;
import org.springframework.web.multipart.MultipartFile;
import vn.azteam.tpf.Constants.Constants;
import vn.azteam.tpf.service.TBExampleStampQueryService; import vn.azteam.tpf.service.TBExampleStampQueryService;
import vn.azteam.tpf.service.TBExampleStampService;
import vn.azteam.tpf.service.UserService; import vn.azteam.tpf.service.UserService;
import vn.azteam.tpf.service.dto.*;
import vn.azteam.tpf.service.dto.TBExampleStampCreationDTO;
import vn.azteam.tpf.service.dto.TBExampleStampCriteria;
import vn.azteam.tpf.service.dto.TBExampleStampDTO;
import vn.azteam.tpf.service.dto.UserDTO;
import vn.azteam.tpf.service.util.PageableUtil; import vn.azteam.tpf.service.util.PageableUtil;
import vn.azteam.tpf.service.util.UserRoleUtil; import vn.azteam.tpf.service.util.UserRoleUtil;
import vn.azteam.tpf.web.rest.errors.BadRequestAlertException; import vn.azteam.tpf.web.rest.errors.BadRequestAlertException;
import vn.azteam.tpf.web.rest.util.HeaderUtil; import vn.azteam.tpf.web.rest.util.HeaderUtil;
import vn.azteam.tpf.web.rest.util.PaginationUtil; import vn.azteam.tpf.web.rest.util.PaginationUtil;
import vn.azteam.tpf.web.rest.util.RandomStringUtil;


import java.net.URI; import java.net.URI;
import java.net.URISyntaxException;
import java.time.Instant; import java.time.Instant;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;


@RestController @RestController


private final UserRoleUtil userRoleUtil; private final UserRoleUtil userRoleUtil;


private final TBExampleStampService tBExampleStampService;

private final UserService userService; private final UserService userService;


private final PageableUtil pageableUtil; private final PageableUtil pageableUtil;


public TBExampleStampResource(TBExampleStampQueryService tBExampleStampQueryService, UserRoleUtil userRoleUtil, UserService userService, PageableUtil pageableUtil){
public TBExampleStampResource(TBExampleStampQueryService tBExampleStampQueryService, UserRoleUtil userRoleUtil,
TBExampleStampService tBExampleStampService, UserService userService, PageableUtil pageableUtil) {


this.tBExampleStampQueryService = tBExampleStampQueryService; this.tBExampleStampQueryService = tBExampleStampQueryService;
this.userRoleUtil = userRoleUtil; this.userRoleUtil = userRoleUtil;
this.tBExampleStampService = tBExampleStampService;
this.userService = userService; this.userService = userService;
this.pageableUtil = pageableUtil; this.pageableUtil = pageableUtil;
} }
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(pageResult, "/api/tb-example-stamp"); HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(pageResult, "/api/tb-example-stamp");
return ResponseEntity.ok().headers(headers).body(pageResult.getContent()); return ResponseEntity.ok().headers(headers).body(pageResult.getContent());
} }

@PostMapping("/tb-example-stamp")
public ResponseEntity<TBExampleStampDTO> create(@RequestPart("data") TBExampleStampCreationDTO tbExampleStampCreationDTO,
@RequestPart("file") MultipartFile file) {

UserDTO currentUser = userService.getCurrentUserDTO().get();
if (file.isEmpty()) {
throw new BadRequestAlertException("1019", ENTITY_NAME, "1019");
}

try {
TBExampleStampDTO tbExampleStampDTO = new TBExampleStampDTO();
tbExampleStampDTO.setY(tbExampleStampCreationDTO.getY());
tbExampleStampDTO.setX(tbExampleStampCreationDTO.getX());
tbExampleStampDTO.setWidth(tbExampleStampCreationDTO.getWidth());
tbExampleStampDTO.setHeight(tbExampleStampCreationDTO.getHeight());
tbExampleStampDTO.setDescription(tbExampleStampCreationDTO.getDescription());
tbExampleStampDTO.setExampleStampName("");
tbExampleStampDTO.setSize(tbExampleStampCreationDTO.getSize());

tbExampleStampDTO.setCreatedDate(Instant.now());
tbExampleStampDTO.setCreatedById(currentUser.getUserId());

TBExampleStampDTO result = null;
Boolean hasViolationException = false;
do {
try {
tbExampleStampDTO = tBExampleStampQueryService.saveUploadedFile(tbExampleStampDTO, file, Constants.EXAMPLE_STAMP);
result = tBExampleStampService.save(tbExampleStampDTO);
} catch (org.springframework.dao.DataIntegrityViolationException ex) {
if (ex.getMessage().contains("ux_tb_example_stamp")) {
hasViolationException = true;
} else {
throw ex;
}
}
}
while (hasViolationException);

return ResponseEntity.created(new URI("/api/tb-example-stamp/" + result.getId()))
.headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString()))
.body(result);
} catch (Exception exception) {
throw new RuntimeException();
}
}
} }

+ 2
- 0
src/main/resources/config/liquibase/sql/20240305_add_column_cert_image_tb_customer.sql 查看文件

ALTER TABLE tb_customer
ADD certification_image varchar(255) null;

Loading…
取消
儲存