| @@ -36,7 +36,7 @@ public class TBCodeDetails implements Serializable { | |||
| @Column(name = "status") | |||
| @Enumerated(value = EnumType.STRING) | |||
| private TBCodeDetailsStatusEnum status = TBCodeDetailsStatusEnum.NEW; | |||
| private TBCodeStatusEnum status = TBCodeStatusEnum.NEW; | |||
| @Column(name = "last_updated_date") | |||
| private Instant lastUpdatedDate; | |||
| @@ -98,11 +98,11 @@ public class TBCodeDetails implements Serializable { | |||
| this.numberScan = numberScan; | |||
| } | |||
| public TBCodeDetailsStatusEnum getStatus() { | |||
| public TBCodeStatusEnum getStatus() { | |||
| return status; | |||
| } | |||
| public void setStatus(TBCodeDetailsStatusEnum status) { | |||
| public void setStatus(TBCodeStatusEnum status) { | |||
| this.status = status; | |||
| } | |||
| @@ -1,19 +0,0 @@ | |||
| package vn.azteam.tpf.domain; | |||
| public enum TBCodeDetailsStatusEnum { | |||
| NEW("NEW"), | |||
| UPDATED("UPDATED"), | |||
| CANCELED("UPDATED_PRINTED"); | |||
| private final String name; | |||
| TBCodeDetailsStatusEnum(final String name) { | |||
| this.name = name; | |||
| } | |||
| public String getName() { | |||
| return name; | |||
| } | |||
| } | |||
| @@ -8,11 +8,7 @@ public enum TBCodeStatusEnum { | |||
| EXPIRED("EXPIRED"), | |||
| CANCELED("CANCELED"), | |||
| UPDATED("UPDATED"), | |||
| UPDATED_PRINTED("UPDATED_PRINTED"); | |||
| CANCELED("CANCELED"); | |||
| @@ -4,6 +4,7 @@ import vn.azteam.tpf.service.dto.TBCodeDetailsDTO; | |||
| import vn.azteam.tpf.web.rest.errors.BadRequestAlertException; | |||
| import java.util.List; | |||
| import java.util.Optional; | |||
| /** | |||
| * Service Interface for managing TBCodeDetailsService. | |||
| @@ -15,4 +16,6 @@ public interface TBCodeDetailsService { | |||
| List<TBCodeDetailsDTO> saveAll(List<TBCodeDetailsDTO> tBCodeDetailsDTOs); | |||
| void updateNumberScan(String code) throws BadRequestAlertException; | |||
| Optional<TBCodeDetailsDTO> updateStatusTBCodeDetails(TBCodeDetailsDTO tBCodeDetailsDTO); | |||
| } | |||
| @@ -1,6 +1,6 @@ | |||
| package vn.azteam.tpf.service.dto; | |||
| import vn.azteam.tpf.domain.TBCodeDetailsStatusEnum; | |||
| import vn.azteam.tpf.domain.TBCodeStatusEnum; | |||
| import java.io.Serializable; | |||
| import java.time.Instant; | |||
| @@ -15,7 +15,7 @@ public class TBCodeDetailsDTO implements Serializable { | |||
| private Integer numberScan; | |||
| private TBCodeDetailsStatusEnum status; | |||
| private TBCodeStatusEnum status; | |||
| private Instant createdDate; | |||
| @@ -61,11 +61,11 @@ public class TBCodeDetailsDTO implements Serializable { | |||
| this.numberScan = numberScan; | |||
| } | |||
| public TBCodeDetailsStatusEnum getStatus() { | |||
| public TBCodeStatusEnum getStatus() { | |||
| return status; | |||
| } | |||
| public void setStatus(TBCodeDetailsStatusEnum status) { | |||
| public void setStatus(TBCodeStatusEnum status) { | |||
| this.status = status; | |||
| } | |||
| @@ -4,8 +4,11 @@ import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import vn.azteam.tpf.domain.TBCode; | |||
| import vn.azteam.tpf.domain.TBCodeDetails; | |||
| import vn.azteam.tpf.domain.TBCodeStatusEnum; | |||
| 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.TBCodeDetailsDTO; | |||
| @@ -31,11 +34,17 @@ public class TBCodeDetailsImpl implements TBCodeDetailsService { | |||
| private final TBCodeDetailsMapper tBCodeDetailsMapper; | |||
| private final TBDetailUserRepository tBDetailUserRepository; | |||
| private final TBCodeDetailsSearchRepository tBCodeDetailsSearchRepository; | |||
| public TBCodeDetailsImpl(TBCodeDetailsRepository tbCodeDetailsRepository, TBCodeDetailsMapper tBCodeDetailsMapper, TBCodeDetailsSearchRepository tBCodeDetailsSearchRepository) { | |||
| public TBCodeDetailsImpl(TBCodeDetailsRepository tbCodeDetailsRepository, | |||
| TBCodeDetailsMapper tBCodeDetailsMapper, | |||
| TBDetailUserRepository tBDetailUserRepository, | |||
| TBCodeDetailsSearchRepository tBCodeDetailsSearchRepository) { | |||
| this.tbCodeDetailsRepository = tbCodeDetailsRepository; | |||
| this.tBCodeDetailsMapper = tBCodeDetailsMapper; | |||
| this.tBDetailUserRepository = tBDetailUserRepository; | |||
| this.tBCodeDetailsSearchRepository = tBCodeDetailsSearchRepository; | |||
| } | |||
| @@ -66,9 +75,12 @@ public class TBCodeDetailsImpl implements TBCodeDetailsService { | |||
| Optional<TBCodeDetails> tbCodeDetailsOptional = tbCodeDetailsRepository.findByCode(code); | |||
| if (tbCodeDetailsOptional.isPresent()) { | |||
| TBCodeDetails tbCodeDetails = tbCodeDetailsOptional.get(); | |||
| if(tbCodeDetails.getTbCode() != null) { | |||
| 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); | |||
| } | |||
| Integer numberScan = tbCodeDetails.getNumberScan(); | |||
| tbCodeDetails.setNumberScan(numberScan.equals(0) ? 1 : numberScan + 1); | |||
| tbCodeDetails.setLastUpdatedDate(Instant.now()); | |||
| @@ -79,4 +91,30 @@ public class TBCodeDetailsImpl implements TBCodeDetailsService { | |||
| } | |||
| } | |||
| @Override | |||
| public Optional<TBCodeDetailsDTO> updateStatusTBCodeDetails(TBCodeDetailsDTO tBCodeDetailsDTO) { | |||
| log.debug("Request to updateStatusTBCodeDetails TBCodeDetails id: {}", tBCodeDetailsDTO.getId()); | |||
| try { | |||
| Optional<TBCodeDetails> tbCodeDetailsOptional = tbCodeDetailsRepository.findById(tBCodeDetailsDTO.getId()); | |||
| if (!tbCodeDetailsOptional.isPresent()) { | |||
| throw new BadRequestAlertException("Not found TBCodeDetails", "", | |||
| tBCodeDetailsDTO.getId().toString()); | |||
| } | |||
| if (tbCodeDetailsOptional.get().getStatus().equals(TBCodeStatusEnum.EXPIRED)) { | |||
| throw new BadRequestAlertException("Bad request, could not change status Canceled or Expired", "", | |||
| tBCodeDetailsDTO.getId().toString()); | |||
| } | |||
| TBCodeDetails tbCodeDetails = tbCodeDetailsOptional.get(); | |||
| tbCodeDetails.setStatus(tBCodeDetailsDTO.getStatus()); | |||
| tbCodeDetails.setModifiedBy(tBDetailUserRepository.findById(tBCodeDetailsDTO.getModifiedById()).get()); | |||
| tbCodeDetails.setModifiedDate(Instant.now()); | |||
| tbCodeDetails = tbCodeDetailsRepository.save(tbCodeDetails); | |||
| return Optional.ofNullable(tBCodeDetailsMapper.toDto(tbCodeDetails)); | |||
| } catch (Exception exception) { | |||
| throw new RuntimeException(); | |||
| } | |||
| } | |||
| } | |||
| @@ -5,7 +5,9 @@ import org.slf4j.LoggerFactory; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import vn.azteam.tpf.domain.TBCode; | |||
| 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.search.TBCodeSearchRepository; | |||
| import vn.azteam.tpf.service.TBCodeService; | |||
| @@ -31,13 +33,17 @@ public class TBCodeServiceImpl implements TBCodeService { | |||
| private final TBCodeRepository tbCodeRepository; | |||
| private final TBCodeDetailsRepository tbCodeDetailsRepository; | |||
| private final TBCodeMapper tBCodeMapper; | |||
| private final TBCodeSearchRepository tBCodeSearchRepository; | |||
| public TBCodeServiceImpl(TBCodeRepository tbCodeRepository, | |||
| TBCodeMapper tBCodeMapper, TBCodeSearchRepository tBCodeSearchRepository) { | |||
| TBCodeDetailsRepository tbCodeDetailsRepository, TBCodeMapper tBCodeMapper, | |||
| TBCodeSearchRepository tBCodeSearchRepository) { | |||
| this.tbCodeRepository = tbCodeRepository; | |||
| this.tbCodeDetailsRepository = tbCodeDetailsRepository; | |||
| this.tBCodeMapper = tBCodeMapper; | |||
| this.tBCodeSearchRepository = tBCodeSearchRepository; | |||
| } | |||
| @@ -77,20 +83,33 @@ public class TBCodeServiceImpl implements TBCodeService { | |||
| @Transactional(readOnly = true) | |||
| public Optional<TBCodeDTO> updateStatusTBCode(TBCodeDTO tbCodeDTO) { | |||
| log.debug("Request to updateTBCode TBCode id: {}", tbCodeDTO.getId()); | |||
| Optional<TBCode> tbCodeOptional = tbCodeRepository.findById(tbCodeDTO.getId()); | |||
| if (!tbCodeOptional.isPresent()) { | |||
| throw new BadRequestAlertException("Not found TBCode", "", | |||
| tbCodeDTO.getId().toString()); | |||
| } | |||
| try { | |||
| Optional<TBCode> tbCodeOptional = tbCodeRepository.findById(tbCodeDTO.getId()); | |||
| if (!tbCodeOptional.isPresent()) { | |||
| throw new BadRequestAlertException("Not found TBCode", "", | |||
| tbCodeDTO.getId().toString()); | |||
| } | |||
| if (TBCodeStatusEnum.CANCELED.equals(tbCodeOptional.get().getStatus()) || | |||
| tbCodeOptional.get().getStatus().equals(TBCodeStatusEnum.EXPIRED)) { | |||
| throw new BadRequestAlertException("Bad request, could not change status Canceled or Expired", "", | |||
| tbCodeDTO.getId().toString()); | |||
| } | |||
| if (TBCodeStatusEnum.CANCELED.equals(tbCodeOptional.get().getStatus()) || | |||
| tbCodeOptional.get().getStatus().equals(TBCodeStatusEnum.EXPIRED)) { | |||
| throw new BadRequestAlertException("Bad request, could not change status Canceled or Expired", "", | |||
| tbCodeDTO.getId().toString()); | |||
| TBCode tbCode = tBCodeMapper.toEntity(tbCodeDTO); | |||
| tbCode = tbCodeRepository.save(tbCode); | |||
| if (!tbCode.getTbCodeDetails().isEmpty()) { | |||
| List<TBCodeDetails> tbCodeDetailsList = new ArrayList<>(); | |||
| for (TBCodeDetails tbCodeDetails : tbCode.getTbCodeDetails()) { | |||
| tbCodeDetails.setStatus(tbCode.getStatus()); | |||
| tbCodeDetailsList.add(tbCodeDetails); | |||
| } | |||
| tbCodeDetailsRepository.saveAll(tbCodeDetailsList); | |||
| } | |||
| return Optional.ofNullable(tBCodeMapper.toDto(tbCode)); | |||
| } catch (Exception exception) { | |||
| throw new RuntimeException(); | |||
| } | |||
| TBCode tbCode = tBCodeMapper.toEntity(tbCodeDTO); | |||
| tbCode = tbCodeRepository.save(tbCode); | |||
| return Optional.ofNullable(tBCodeMapper.toDto(tbCode)); | |||
| } | |||
| } | |||
| @@ -1,23 +1,30 @@ | |||
| package vn.azteam.tpf.web.rest; | |||
| import com.codahale.metrics.annotation.Timed; | |||
| import io.github.jhipster.web.util.ResponseUtil; | |||
| import io.searchbox.strings.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.http.ResponseEntity; | |||
| import org.springframework.web.bind.annotation.GetMapping; | |||
| import org.springframework.web.bind.annotation.PathVariable; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import vn.azteam.tpf.domain.TBCodeStatusEnum; | |||
| import vn.azteam.tpf.service.TBCodeDetailsQueryService; | |||
| import vn.azteam.tpf.service.TBCodeDetailsService; | |||
| import vn.azteam.tpf.service.UserService; | |||
| import vn.azteam.tpf.service.dto.TBCodeDetailsDTO; | |||
| import vn.azteam.tpf.service.dto.UserDTO; | |||
| import vn.azteam.tpf.service.util.PageableUtil; | |||
| import vn.azteam.tpf.service.util.UserRoleUtil; | |||
| import vn.azteam.tpf.web.rest.errors.BadRequestAlertException; | |||
| import java.time.Instant; | |||
| import java.util.Optional; | |||
| @RestController | |||
| @RequestMapping("/api") | |||
| public class TBCodeDetailsResource { | |||
| private static final String ENTITY_NAME = "tBCodeDetails"; | |||
| private final Logger log = LoggerFactory.getLogger(TBCodeDetailsResource.class); | |||
| private final TBCodeDetailsService tBCodeDetailsService; | |||
| @@ -28,21 +35,52 @@ public class TBCodeDetailsResource { | |||
| private final PageableUtil pageableUtil; | |||
| private final UserService userService; | |||
| public TBCodeDetailsResource(TBCodeDetailsService tBCodeDetailsService, TBCodeDetailsQueryService tBCodeDetailsQueryService, UserRoleUtil userRoleUtil, PageableUtil pageableUtil) { | |||
| public TBCodeDetailsResource(TBCodeDetailsService tBCodeDetailsService, TBCodeDetailsQueryService tBCodeDetailsQueryService, | |||
| UserRoleUtil userRoleUtil, PageableUtil pageableUtil, UserService userService) { | |||
| this.tBCodeDetailsService = tBCodeDetailsService; | |||
| this.tBCodeDetailsQueryService = tBCodeDetailsQueryService; | |||
| this.userRoleUtil = userRoleUtil; | |||
| this.pageableUtil = pageableUtil; | |||
| this.userService = userService; | |||
| } | |||
| @GetMapping("/tb-codes-scan/{code}") | |||
| @GetMapping("/tb-code-details/scan/{code}") | |||
| @Timed | |||
| public ResponseEntity<?> getTBCodeScan(@PathVariable String code) { | |||
| public ResponseEntity<?> getTBCodeDetailsScan(@PathVariable String code) { | |||
| if (StringUtils.isBlank(code)) { | |||
| return (ResponseEntity<?>) ResponseEntity.badRequest(); | |||
| } | |||
| tBCodeDetailsService.updateNumberScan(code); | |||
| return ResponseEntity.ok().build(); | |||
| } | |||
| @PutMapping("/tb-code-details/update/{id}/status/{status}") | |||
| @Timed | |||
| public ResponseEntity<TBCodeDetailsDTO> updateTBCodeDetailsStatus(@PathVariable Long id, @PathVariable String status) { | |||
| log.debug("REST request to update tb codes : {}, status {} ", id, status); | |||
| if (id == null || org.apache.commons.lang3.StringUtils.isBlank(status)) { | |||
| throw new BadRequestAlertException("1039", ENTITY_NAME, "1039"); | |||
| } | |||
| try { | |||
| TBCodeStatusEnum.valueOf(status); | |||
| } catch (Exception exception) { | |||
| throw new BadRequestAlertException("1039", ENTITY_NAME, "1039"); | |||
| } | |||
| UserDTO currentUser = userService.getCurrentUserDTO().get(); | |||
| TBCodeDetailsDTO tbCodeDetailsDTO = new TBCodeDetailsDTO(); | |||
| tbCodeDetailsDTO.setId(id); | |||
| tbCodeDetailsDTO.setModifiedDate(Instant.now()); | |||
| tbCodeDetailsDTO.setModifiedById(currentUser.getId()); | |||
| tbCodeDetailsDTO.setStatus(TBCodeStatusEnum.valueOf(status)); | |||
| Optional<TBCodeDetailsDTO> tBCodeUpdated = | |||
| tBCodeDetailsService.updateStatusTBCodeDetails(tbCodeDetailsDTO); | |||
| // if (null != tBCropDTO) { | |||
| // sendNotificationPersonInCharge(cropPersonInChargeDTO, listAssignmentPrev); | |||
| // } | |||
| return ResponseUtil.wrapOrNotFound(tBCodeUpdated); | |||
| } | |||
| } | |||
| @@ -10,7 +10,6 @@ import org.springframework.data.domain.Pageable; | |||
| import org.springframework.http.HttpHeaders; | |||
| import org.springframework.http.ResponseEntity; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import vn.azteam.tpf.domain.TBCodeDetailsStatusEnum; | |||
| import vn.azteam.tpf.domain.TBCodeStatusEnum; | |||
| import vn.azteam.tpf.service.*; | |||
| import vn.azteam.tpf.service.dto.*; | |||
| @@ -170,7 +169,7 @@ public class TBCodeResource { | |||
| codeDetailsDTO.setCode(tBCodeDTO.getCode()); | |||
| codeDetailsDTO.setTbCode(tBCodeDTO); | |||
| codeDetailsDTO.setNumberScan(0); | |||
| codeDetailsDTO.setStatus(TBCodeDetailsStatusEnum.NEW); | |||
| codeDetailsDTO.setStatus(TBCodeStatusEnum.NEW); | |||
| codeDetailsDTO.setCreatedDate(Instant.now()); | |||
| tBCodeDTO.setCreatedById(currentUser.getUserId()); | |||
| tbCodeDetailsDTOS.add(codeDetailsDTO); | |||
| @@ -206,7 +205,7 @@ public class TBCodeResource { | |||
| */ | |||
| @PutMapping("/tb-codes/update/{id}/status/{status}") | |||
| @Timed | |||
| public ResponseEntity<TBCodeDTO> updateTBCode(@PathVariable Long id, String status) { | |||
| public ResponseEntity<TBCodeDTO> updateTBCode(@PathVariable Long id, @PathVariable String status) { | |||
| log.debug("REST request to update tb codes : {}, status {} ", id, status); | |||
| if (id == null || StringUtils.isBlank(status)) { | |||
| throw new BadRequestAlertException("1039", ENTITY_NAME, "1039"); | |||