| @@ -1,5 +1,6 @@ | |||
| package vn.azteam.tpf.service; | |||
| import vn.azteam.tpf.service.dto.TBCodeDetailsCreationDTO; | |||
| import vn.azteam.tpf.service.dto.TBCodeDetailsDTO; | |||
| import vn.azteam.tpf.web.rest.errors.BadRequestAlertException; | |||
| @@ -13,7 +14,7 @@ import java.util.Optional; | |||
| public interface TBCodeDetailsService { | |||
| TBCodeDetailsDTO save(TBCodeDetailsDTO tBCodeDetailsDTO); | |||
| List<TBCodeDetailsDTO> saveAll(List<TBCodeDetailsDTO> tBCodeDetailsDTOs); | |||
| List<TBCodeDetailsDTO> saveAll(List<TBCodeDetailsCreationDTO> tBCodeDetailsDTOs); | |||
| void updateNumberScan(String code) throws BadRequestAlertException; | |||
| @@ -0,0 +1,118 @@ | |||
| package vn.azteam.tpf.service.dto; | |||
| import vn.azteam.tpf.domain.TBCodeStatusEnum; | |||
| import java.io.Serializable; | |||
| import java.time.Instant; | |||
| public class TBCodeDetailsCreationDTO implements Serializable { | |||
| private Long id; | |||
| private TBCodeDTO tbCode; | |||
| private String code; | |||
| private Integer numberScan; | |||
| private TBCodeStatusEnum status; | |||
| private Instant createdDate; | |||
| private Instant modifiedDate; | |||
| private Instant deletedDate; | |||
| private Long createdById; | |||
| private Long modifiedById; | |||
| private Long deletedById; | |||
| public Long getId() { | |||
| return id; | |||
| } | |||
| public void setId(Long id) { | |||
| this.id = id; | |||
| } | |||
| public TBCodeDTO getTbCode() { | |||
| return tbCode; | |||
| } | |||
| public void setTbCode(TBCodeDTO tbCode) { | |||
| this.tbCode = tbCode; | |||
| } | |||
| public String getCode() { | |||
| return code; | |||
| } | |||
| public void setCode(String code) { | |||
| this.code = code; | |||
| } | |||
| public Integer getNumberScan() { | |||
| return numberScan; | |||
| } | |||
| public void setNumberScan(Integer numberScan) { | |||
| this.numberScan = numberScan; | |||
| } | |||
| public TBCodeStatusEnum getStatus() { | |||
| return status; | |||
| } | |||
| public void setStatus(TBCodeStatusEnum status) { | |||
| this.status = status; | |||
| } | |||
| public Instant getCreatedDate() { | |||
| return createdDate; | |||
| } | |||
| public void setCreatedDate(Instant createdDate) { | |||
| this.createdDate = createdDate; | |||
| } | |||
| public Instant getModifiedDate() { | |||
| return modifiedDate; | |||
| } | |||
| public void setModifiedDate(Instant modifiedDate) { | |||
| this.modifiedDate = modifiedDate; | |||
| } | |||
| public Instant getDeletedDate() { | |||
| return deletedDate; | |||
| } | |||
| public void setDeletedDate(Instant deletedDate) { | |||
| this.deletedDate = deletedDate; | |||
| } | |||
| public Long getCreatedById() { | |||
| return createdById; | |||
| } | |||
| public void setCreatedById(Long createdById) { | |||
| this.createdById = createdById; | |||
| } | |||
| public Long getModifiedById() { | |||
| return modifiedById; | |||
| } | |||
| public void setModifiedById(Long modifiedById) { | |||
| this.modifiedById = modifiedById; | |||
| } | |||
| public Long getDeletedById() { | |||
| return deletedById; | |||
| } | |||
| public void setDeletedById(Long deletedById) { | |||
| this.deletedById = deletedById; | |||
| } | |||
| } | |||
| @@ -9,8 +9,6 @@ public class TBCodeDetailsDTO implements Serializable { | |||
| private Long id; | |||
| private TBCodeDTO tbCode; | |||
| private String code; | |||
| private Integer numberScan; | |||
| @@ -37,14 +35,6 @@ public class TBCodeDetailsDTO implements Serializable { | |||
| this.id = id; | |||
| } | |||
| public TBCodeDTO getTbCode() { | |||
| return tbCode; | |||
| } | |||
| public void setTbCode(TBCodeDTO tbCode) { | |||
| this.tbCode = tbCode; | |||
| } | |||
| public String getCode() { | |||
| return code; | |||
| } | |||
| @@ -11,6 +11,7 @@ import vn.azteam.tpf.repository.TBCodeDetailsRepository; | |||
| import vn.azteam.tpf.repository.TBDetailUserRepository; | |||
| import vn.azteam.tpf.repository.search.TBCodeDetailsSearchRepository; | |||
| import vn.azteam.tpf.service.TBCodeDetailsService; | |||
| import vn.azteam.tpf.service.dto.TBCodeDetailsCreationDTO; | |||
| import vn.azteam.tpf.service.dto.TBCodeDetailsDTO; | |||
| import vn.azteam.tpf.service.mapper.TBCodeDetailsMapper; | |||
| import vn.azteam.tpf.web.rest.errors.BadRequestAlertException; | |||
| @@ -49,6 +50,7 @@ public class TBCodeDetailsImpl implements TBCodeDetailsService { | |||
| } | |||
| @Override | |||
| @Transactional | |||
| public TBCodeDetailsDTO save(TBCodeDetailsDTO tBCodeDetailsDTO) { | |||
| log.debug("Request to save TBCodeDetailsDTO : {}", tBCodeDetailsDTO); | |||
| @@ -61,9 +63,9 @@ public class TBCodeDetailsImpl implements TBCodeDetailsService { | |||
| @Override | |||
| @Transactional | |||
| public List<TBCodeDetailsDTO> saveAll(List<TBCodeDetailsDTO> tBCodeDetailsDTOs) { | |||
| public List<TBCodeDetailsDTO> saveAll(List<TBCodeDetailsCreationDTO> tBCodeDetailsDTOs) { | |||
| List<TBCodeDetails> tbCodes = new ArrayList<>(); | |||
| for (TBCodeDetailsDTO tBCodeDetailsDTO : tBCodeDetailsDTOs) { | |||
| for (TBCodeDetailsCreationDTO tBCodeDetailsDTO : tBCodeDetailsDTOs) { | |||
| TBCodeDetails tbCodeDetails = tBCodeDetailsMapper.toEntity(tBCodeDetailsDTO); | |||
| tbCodes.add(tbCodeDetails); | |||
| } | |||
| @@ -71,7 +73,7 @@ public class TBCodeDetailsImpl implements TBCodeDetailsService { | |||
| return tbCodes.stream().map(tBCodeDetailsMapper::toDto).collect(Collectors.toList()); | |||
| } | |||
| @Transactional(readOnly = true) | |||
| @Transactional | |||
| public void updateNumberScan(String code) throws BadRequestAlertException { | |||
| Optional<TBCodeDetails> tbCodeDetailsOptional = tbCodeDetailsRepository.findByCode(code); | |||
| if (tbCodeDetailsOptional.isPresent()) { | |||
| @@ -79,7 +81,7 @@ public class TBCodeDetailsImpl implements TBCodeDetailsService { | |||
| TBCode tbCode = tbCodeDetails.getTbCode(); | |||
| if (!TBCodeStatusEnum.ACTIVE.getName().equals(tbCodeDetails.getStatus().getName()) || | |||
| tbCode.getExpiredDate().isBefore(Instant.now())) { | |||
| throw new BadRequestAlertException("Not found", "tb code details to update with code:", code); | |||
| throw new BadRequestAlertException("Scan error", "tb code details to scan with code:", code); | |||
| } | |||
| Integer numberScan = tbCodeDetails.getNumberScan(); | |||
| @@ -88,11 +90,12 @@ public class TBCodeDetailsImpl implements TBCodeDetailsService { | |||
| tbCodeDetailsRepository.save(tbCodeDetails); | |||
| log.debug("update number scan find by criteria code : {}", code); | |||
| } else { | |||
| throw new BadRequestAlertException("Not found", "tb code details to update with code:", code); | |||
| throw new BadRequestAlertException("Scan code not found", "tb code details with code:", code); | |||
| } | |||
| } | |||
| @Override | |||
| @Transactional | |||
| public Optional<TBCodeDetailsDTO> updateStatusTBCodeDetails(TBCodeDetailsDTO tBCodeDetailsDTO) { | |||
| log.debug("Request to updateStatusTBCodeDetails TBCodeDetails id: {}", tBCodeDetailsDTO.getId()); | |||
| try { | |||
| @@ -117,5 +120,4 @@ public class TBCodeDetailsImpl implements TBCodeDetailsService { | |||
| throw new RuntimeException(); | |||
| } | |||
| } | |||
| } | |||
| @@ -9,17 +9,22 @@ import vn.azteam.tpf.domain.TBCodeDetails; | |||
| import vn.azteam.tpf.domain.TBCodeStatusEnum; | |||
| import vn.azteam.tpf.repository.TBCodeDetailsRepository; | |||
| import vn.azteam.tpf.repository.TBCodeRepository; | |||
| import vn.azteam.tpf.repository.TBDetailUserRepository; | |||
| import vn.azteam.tpf.repository.search.TBCodeSearchRepository; | |||
| import vn.azteam.tpf.service.TBCodeDetailsService; | |||
| import vn.azteam.tpf.service.TBCodeService; | |||
| import vn.azteam.tpf.service.dto.TBCodeDTO; | |||
| import vn.azteam.tpf.service.dto.TBCodeDetailsCreationDTO; | |||
| import vn.azteam.tpf.service.dto.TBCodeDetailsDTO; | |||
| import vn.azteam.tpf.service.mapper.TBCodeMapper; | |||
| import vn.azteam.tpf.web.rest.errors.BadRequestAlertException; | |||
| import vn.azteam.tpf.web.rest.util.RandomStringUtil; | |||
| import java.time.Instant; | |||
| import java.util.*; | |||
| import java.util.ArrayList; | |||
| import java.util.HashSet; | |||
| import java.util.List; | |||
| import java.util.Optional; | |||
| import java.util.stream.Collectors; | |||
| /** | |||
| @@ -42,15 +47,18 @@ public class TBCodeServiceImpl implements TBCodeService { | |||
| private final TBCodeMapper tBCodeMapper; | |||
| private final TBCodeSearchRepository tBCodeSearchRepository; | |||
| private final TBDetailUserRepository tBDetailUserRepository; | |||
| public TBCodeServiceImpl(TBCodeRepository tbCodeRepository, | |||
| TBCodeDetailsRepository tbCodeDetailsRepository, TBCodeDetailsService tbCodeDetailsService, TBCodeMapper tBCodeMapper, | |||
| TBCodeSearchRepository tBCodeSearchRepository) { | |||
| TBCodeSearchRepository tBCodeSearchRepository, | |||
| TBDetailUserRepository tBDetailUserRepository) { | |||
| this.tbCodeRepository = tbCodeRepository; | |||
| this.tbCodeDetailsRepository = tbCodeDetailsRepository; | |||
| this.tbCodeDetailsService = tbCodeDetailsService; | |||
| this.tBCodeMapper = tBCodeMapper; | |||
| this.tBCodeSearchRepository = tBCodeSearchRepository; | |||
| this.tBDetailUserRepository = tBDetailUserRepository; | |||
| } | |||
| @@ -65,25 +73,26 @@ public class TBCodeServiceImpl implements TBCodeService { | |||
| tBCodeSearchRepository.save(tbCode); | |||
| if (tbCode.getId() != null) { | |||
| List<TBCodeDetailsDTO> tbCodeDetailsDTOS = new ArrayList<>(); | |||
| List<TBCodeDetailsCreationDTO> tbCodeDetailsDTOS = new ArrayList<>(); | |||
| for (int i = 1; i <= tbCode.getQuantity(); i++) { | |||
| TBCodeDetailsDTO codeDetailsDTO = new TBCodeDetailsDTO(); | |||
| TBCodeDetailsCreationDTO codeDetailsDTO = new TBCodeDetailsCreationDTO(); | |||
| codeDetailsDTO.setCode(String.valueOf(RandomStringUtil.getDigitCodeDetail())); | |||
| codeDetailsDTO.setTbCode(result); | |||
| codeDetailsDTO.setNumberScan(0); | |||
| codeDetailsDTO.setStatus(TBCodeStatusEnum.NEW); | |||
| codeDetailsDTO.setCreatedDate(Instant.now()); | |||
| tBCodeDTO.setCreatedById(tBCodeDTO.getCreatedById()); | |||
| codeDetailsDTO.setCreatedById(tBCodeDTO.getCreatedById()); | |||
| tbCodeDetailsDTOS.add(codeDetailsDTO); | |||
| } | |||
| tbCodeDetailsDTOS = tbCodeDetailsService.saveAll(tbCodeDetailsDTOS); | |||
| result.setTbCodeDetails(new HashSet<>(tbCodeDetailsDTOS)); | |||
| List<TBCodeDetailsDTO> data = tbCodeDetailsService.saveAll(tbCodeDetailsDTOS); | |||
| result.setTbCodeDetails(new HashSet<>(data)); | |||
| } | |||
| return result; | |||
| } | |||
| @Override | |||
| @Transactional() | |||
| public List<TBCodeDTO> saveAll(List<TBCodeDTO> tBCodeDTOs) { | |||
| List<TBCode> tbCodes = new ArrayList<>(); | |||
| for (TBCodeDTO tbCodeDTO : tBCodeDTOs) { | |||
| @@ -95,7 +104,7 @@ public class TBCodeServiceImpl implements TBCodeService { | |||
| } | |||
| @Override | |||
| @Transactional(readOnly = true) | |||
| @Transactional | |||
| public Optional<TBCodeDTO> findOne(Long id) { | |||
| log.debug("Request to get TBCode : {}", id); | |||
| return tbCodeRepository.findById(id) | |||
| @@ -103,7 +112,7 @@ public class TBCodeServiceImpl implements TBCodeService { | |||
| } | |||
| @Override | |||
| @Transactional(readOnly = true) | |||
| @Transactional() | |||
| public Optional<TBCodeDTO> updateStatusTBCode(TBCodeDTO tbCodeDTO) { | |||
| log.debug("Request to updateTBCode TBCode id: {}", tbCodeDTO.getId()); | |||
| try { | |||
| @@ -119,7 +128,10 @@ public class TBCodeServiceImpl implements TBCodeService { | |||
| tbCodeDTO.getId().toString()); | |||
| } | |||
| TBCode tbCode = tBCodeMapper.toEntity(tbCodeDTO); | |||
| TBCode tbCode = tbCodeOptional.get(); | |||
| tbCode.setStatus(tbCodeDTO.getStatus()); | |||
| tbCode.setModifiedDate(tbCodeDTO.getModifiedDate()); | |||
| tbCode.setModifiedBy(tBDetailUserRepository.getOne(tbCodeDTO.getId())); | |||
| tbCode = tbCodeRepository.save(tbCode); | |||
| if (!tbCode.getTbCodeDetails().isEmpty()) { | |||
| @@ -3,6 +3,7 @@ package vn.azteam.tpf.service.mapper; | |||
| import org.mapstruct.Mapper; | |||
| import org.mapstruct.Mapping; | |||
| import vn.azteam.tpf.domain.TBCodeDetails; | |||
| import vn.azteam.tpf.service.dto.TBCodeDetailsCreationDTO; | |||
| import vn.azteam.tpf.service.dto.TBCodeDetailsDTO; | |||
| @Mapper(componentModel = "spring", uses = {TBDetailUserMapper.class}) | |||
| @@ -12,12 +13,17 @@ public interface TBCodeDetailsMapper extends EntityMapper<TBCodeDetailsDTO, TBCo | |||
| @Mapping(source = "deletedBy.id", target = "deletedById") | |||
| TBCodeDetailsDTO toDto(TBCodeDetails tBCodeDetails); | |||
| @Mapping(source = "tbCode", target = "tbCode") | |||
| @Mapping(source = "createdById", target = "createdBy") | |||
| @Mapping(source = "modifiedById", target = "modifiedBy") | |||
| @Mapping(source = "deletedById", target = "deletedBy") | |||
| TBCodeDetails toEntity(TBCodeDetailsDTO tBCodeDetailsDTO); | |||
| @Mapping(source = "tbCode", target = "tbCode") | |||
| @Mapping(source = "createdById", target = "createdBy") | |||
| @Mapping(source = "modifiedById", target = "modifiedBy") | |||
| @Mapping(source = "deletedById", target = "deletedBy") | |||
| TBCodeDetails toEntity(TBCodeDetailsCreationDTO tBCodeDetailsDTO); | |||
| default TBCodeDetails fromId(Long id) { | |||
| if (id == null) { | |||
| return null; | |||