| @@ -38,6 +38,9 @@ public class TBCodeDetails implements Serializable { | |||
| @Enumerated(value = EnumType.STRING) | |||
| private TBCodeDetailsStatusEnum status = TBCodeDetailsStatusEnum.NEW; | |||
| @Column(name = "last_updated_date") | |||
| private Instant lastUpdatedDate; | |||
| @Column(name = "created_date") | |||
| private Instant createdDate; | |||
| @@ -150,4 +153,12 @@ public class TBCodeDetails implements Serializable { | |||
| public void setDeletedBy(TBDetailUser deletedBy) { | |||
| this.deletedBy = deletedBy; | |||
| } | |||
| public Instant getLastUpdatedDate() { | |||
| return lastUpdatedDate; | |||
| } | |||
| public void setLastUpdatedDate(Instant lastUpdatedDate) { | |||
| this.lastUpdatedDate = lastUpdatedDate; | |||
| } | |||
| } | |||
| @@ -4,10 +4,16 @@ public enum TBCodeStatusEnum { | |||
| NEW("NEW"), | |||
| ACTIVE("ACTIVE"), | |||
| CANCELED("CANCELED"), | |||
| UPDATED("UPDATED"), | |||
| UPDATED_PRINTED("UPDATED_PRINTED"); | |||
| private final String name; | |||
| TBCodeStatusEnum(final String name) { | |||
| @@ -5,6 +5,12 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | |||
| import org.springframework.stereotype.Repository; | |||
| import vn.azteam.tpf.domain.TBCodeDetails; | |||
| import java.util.Optional; | |||
| @Repository | |||
| public interface TBCodeDetailsRepository extends JpaRepository<TBCodeDetails, Long>, JpaSpecificationExecutor<TBCodeDetails> { | |||
| // @Query("select tb_code_details from TBCodeDetails tb_code_details where tb_code_details.code =:code") | |||
| Optional<TBCodeDetails> findByCode(String code); | |||
| } | |||
| @@ -2,10 +2,16 @@ package vn.azteam.tpf.repository; | |||
| import org.springframework.data.jpa.repository.JpaRepository; | |||
| import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | |||
| import org.springframework.data.repository.query.Param; | |||
| import org.springframework.stereotype.Repository; | |||
| import vn.azteam.tpf.domain.TBCode; | |||
| import vn.azteam.tpf.domain.TBCrop; | |||
| import java.util.Optional; | |||
| @Repository | |||
| public interface TBCodeRepository extends JpaRepository<TBCode, Long>, JpaSpecificationExecutor<TBCode> { | |||
| public interface TBCodeRepository extends JpaRepository<TBCode, Long>, JpaSpecificationExecutor<TBCode> { | |||
| //@Query("select tb_crop from TBCrop tb_crop left join fetch tb_crop.tbDetailUsers where tb_crop.id =:id") | |||
| Optional<TBCode> findOneWithEagerRelationships(@Param("id") Long id); | |||
| } | |||
| @@ -8,10 +8,7 @@ import org.springframework.data.domain.Pageable; | |||
| import org.springframework.data.jpa.domain.Specification; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import vn.azteam.tpf.domain.TBCodeDetails; | |||
| import vn.azteam.tpf.domain.TBCodeDetails_; | |||
| import vn.azteam.tpf.domain.TBDetailUser; | |||
| import vn.azteam.tpf.domain.TBDetailUser_; | |||
| import vn.azteam.tpf.domain.*; | |||
| import vn.azteam.tpf.repository.TBCodeDetailsRepository; | |||
| import vn.azteam.tpf.service.dto.TBCodeDetailsCriteria; | |||
| import vn.azteam.tpf.service.dto.TBCodeDetailsDTO; | |||
| @@ -19,6 +16,7 @@ import vn.azteam.tpf.service.mapper.TBCodeDetailsMapper; | |||
| import javax.persistence.criteria.Join; | |||
| import javax.persistence.criteria.JoinType; | |||
| import java.util.Optional; | |||
| @Service | |||
| @Transactional(readOnly = true) | |||
| @@ -44,6 +42,13 @@ public class TBCodeDetailsQueryService extends QueryService<TBCodeDetails> { | |||
| .map(tBCodeDetailsMapper::toDto); | |||
| } | |||
| @Transactional(readOnly = true) | |||
| public Optional<TBCodeDetailsDTO> findByCode(String code) { | |||
| log.debug("find by criteria code : {}", code); | |||
| return tBCodeDetailsRepository.findByCode(code) | |||
| .map(tBCodeDetailsMapper::toDto); | |||
| } | |||
| private Specification<TBCodeDetails> initializeCropSpecification() { | |||
| return (Specification<TBCodeDetails>) (root, query, cb) -> { | |||
| final Join<TBCodeDetails, TBDetailUser> detailUserJoin = root.join(TBCodeDetails_.deletedBy, JoinType.LEFT); | |||
| @@ -52,7 +57,7 @@ public class TBCodeDetailsQueryService extends QueryService<TBCodeDetails> { | |||
| } | |||
| /** | |||
| * Function to convert TBCodeCriteria to a {@link Specification} | |||
| * Function to convert TBCodeDetailCriteria to a {@link Specification} | |||
| */ | |||
| private Specification<TBCodeDetails> createSpecification(TBCodeDetailsCriteria criteria) { | |||
| Specification<TBCodeDetails> specification = initializeCropSpecification(); | |||
| @@ -63,9 +68,9 @@ public class TBCodeDetailsQueryService extends QueryService<TBCodeDetails> { | |||
| // if (criteria.getQrCode() != null) { | |||
| // specification = specification.and(buildStringSpecification(criteria.getQrCode(), TBCrop_.qrCode)); | |||
| // } | |||
| // if (criteria.getCode() != null) { | |||
| // specification = specification.and(buildStringSpecification(criteria.getCode(), TBCrop_.code)); | |||
| // } | |||
| if (criteria.getCode() != null) { | |||
| specification = specification.and(buildStringSpecification(criteria.getCode(), TBCodeDetails_.code)); | |||
| } | |||
| // if (criteria.getAreaM2() != null) { | |||
| // specification = specification.and(buildRangeSpecification(criteria.getAreaM2(), TBCrop_.areaM2)); | |||
| // } | |||
| @@ -1,6 +1,7 @@ | |||
| package vn.azteam.tpf.service; | |||
| import vn.azteam.tpf.service.dto.TBCodeDetailsDTO; | |||
| import vn.azteam.tpf.web.rest.errors.BadRequestAlertException; | |||
| import java.util.List; | |||
| @@ -12,4 +13,6 @@ public interface TBCodeDetailsService { | |||
| TBCodeDetailsDTO save(TBCodeDetailsDTO tBCodeDetailsDTO); | |||
| List<TBCodeDetailsDTO> saveAll(List<TBCodeDetailsDTO> tBCodeDetailsDTOs); | |||
| void updateNumberScan(String code) throws BadRequestAlertException; | |||
| } | |||
| @@ -1,8 +1,12 @@ | |||
| package vn.azteam.tpf.service; | |||
| import vn.azteam.tpf.domain.TBCodeStatusEnum; | |||
| import vn.azteam.tpf.service.dto.TBCodeDTO; | |||
| import vn.azteam.tpf.service.dto.TBCodeUpdateDTO; | |||
| import vn.azteam.tpf.service.dto.TBCropDTO; | |||
| import java.util.List; | |||
| import java.util.Optional; | |||
| /** | |||
| * Service Interface for managing TBCode. | |||
| @@ -12,6 +16,10 @@ public interface TBCodeService { | |||
| List<TBCodeDTO> saveAll(List<TBCodeDTO> tBCodeDTOs); | |||
| Optional<TBCodeDTO> findOne(Long id); | |||
| Optional<TBCodeDTO> updateStatusTBCode(TBCodeDTO tBCodeDTO); | |||
| // /** | |||
| // * Update crop's PIC | |||
| // * @param cropPersonInChargeDTO | |||
| @@ -1,6 +1,7 @@ | |||
| package vn.azteam.tpf.service.dto; | |||
| import java.io.Serializable; | |||
| import java.time.Instant; | |||
| public class TBCodeCreationDTO implements Serializable { | |||
| @@ -12,6 +13,8 @@ public class TBCodeCreationDTO implements Serializable { | |||
| private String description; | |||
| private Instant expiredDate; | |||
| public Long gettBCropId() { | |||
| return tBCropId; | |||
| } | |||
| @@ -43,4 +46,12 @@ public class TBCodeCreationDTO implements Serializable { | |||
| public void setDescription(String description) { | |||
| this.description = description; | |||
| } | |||
| public Instant getExpiredDate() { | |||
| return expiredDate; | |||
| } | |||
| public void setExpiredDate(Instant expiredDate) { | |||
| this.expiredDate = expiredDate; | |||
| } | |||
| } | |||
| @@ -17,8 +17,6 @@ public class TBCodeDetailsDTO implements Serializable { | |||
| private TBCodeDetailsStatusEnum status; | |||
| // private Instant expiredDate; | |||
| private Instant createdDate; | |||
| private Instant modifiedDate; | |||
| @@ -0,0 +1,81 @@ | |||
| package vn.azteam.tpf.service.dto; | |||
| import vn.azteam.tpf.domain.TBCodeStatusEnum; | |||
| import java.io.Serializable; | |||
| import java.time.Instant; | |||
| import java.util.HashSet; | |||
| import java.util.Set; | |||
| public class TBCodeUpdateDTO implements Serializable { | |||
| private Long id; | |||
| private TBCropDTO tbCropDTO; | |||
| private Integer quantity; | |||
| private String description; | |||
| private String pathImage; | |||
| private TBCodeStatusEnum status; | |||
| private Instant expiredDate; | |||
| public Long getId() { | |||
| return id; | |||
| } | |||
| public void setId(Long id) { | |||
| this.id = id; | |||
| } | |||
| public TBCropDTO getTbCropDTO() { | |||
| return tbCropDTO; | |||
| } | |||
| public void setTbCropDTO(TBCropDTO tbCropDTO) { | |||
| this.tbCropDTO = tbCropDTO; | |||
| } | |||
| public Integer getQuantity() { | |||
| return quantity; | |||
| } | |||
| public void setQuantity(Integer quantity) { | |||
| this.quantity = quantity; | |||
| } | |||
| public String getDescription() { | |||
| return description; | |||
| } | |||
| public void setDescription(String description) { | |||
| this.description = description; | |||
| } | |||
| public String getPathImage() { | |||
| return pathImage; | |||
| } | |||
| public void setPathImage(String pathImage) { | |||
| this.pathImage = pathImage; | |||
| } | |||
| public TBCodeStatusEnum getStatus() { | |||
| return status; | |||
| } | |||
| public void setStatus(TBCodeStatusEnum status) { | |||
| this.status = status; | |||
| } | |||
| public Instant getExpiredDate() { | |||
| return expiredDate; | |||
| } | |||
| public void setExpiredDate(Instant expiredDate) { | |||
| this.expiredDate = expiredDate; | |||
| } | |||
| } | |||
| @@ -10,9 +10,12 @@ import vn.azteam.tpf.repository.search.TBCodeDetailsSearchRepository; | |||
| import vn.azteam.tpf.service.TBCodeDetailsService; | |||
| import vn.azteam.tpf.service.dto.TBCodeDetailsDTO; | |||
| import vn.azteam.tpf.service.mapper.TBCodeDetailsMapper; | |||
| import vn.azteam.tpf.web.rest.errors.BadRequestAlertException; | |||
| import java.time.Instant; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| import java.util.Optional; | |||
| import java.util.stream.Collectors; | |||
| /** | |||
| @@ -58,4 +61,22 @@ public class TBCodeDetailsImpl implements TBCodeDetailsService { | |||
| return tbCodes.stream().map(tBCodeDetailsMapper::toDto).collect(Collectors.toList()); | |||
| } | |||
| @Transactional(readOnly = true) | |||
| public void updateNumberScan(String code) throws BadRequestAlertException { | |||
| Optional<TBCodeDetails> tbCodeDetailsOptional = tbCodeDetailsRepository.findByCode(code); | |||
| if (tbCodeDetailsOptional.isPresent()) { | |||
| TBCodeDetails tbCodeDetails = tbCodeDetailsOptional.get(); | |||
| if(tbCodeDetails.getTbCode() != null) { | |||
| } | |||
| Integer numberScan = tbCodeDetails.getNumberScan(); | |||
| tbCodeDetails.setNumberScan(numberScan.equals(0) ? 1 : numberScan + 1); | |||
| tbCodeDetails.setLastUpdatedDate(Instant.now()); | |||
| 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); | |||
| } | |||
| } | |||
| } | |||
| @@ -10,9 +10,11 @@ import vn.azteam.tpf.repository.search.TBCodeSearchRepository; | |||
| import vn.azteam.tpf.service.TBCodeService; | |||
| import vn.azteam.tpf.service.dto.TBCodeDTO; | |||
| import vn.azteam.tpf.service.mapper.TBCodeMapper; | |||
| import vn.azteam.tpf.web.rest.errors.BadRequestAlertException; | |||
| import java.util.ArrayList; | |||
| import java.util.List; | |||
| import java.util.Optional; | |||
| import java.util.stream.Collectors; | |||
| /** | |||
| @@ -32,7 +34,8 @@ public class TBCodeServiceImpl implements TBCodeService { | |||
| private final TBCodeSearchRepository tBCodeSearchRepository; | |||
| public TBCodeServiceImpl(TBCodeRepository tbCodeRepository, TBCodeMapper tBCodeMapper, TBCodeSearchRepository tBCodeSearchRepository) { | |||
| public TBCodeServiceImpl(TBCodeRepository tbCodeRepository, | |||
| TBCodeMapper tBCodeMapper, TBCodeSearchRepository tBCodeSearchRepository) { | |||
| this.tbCodeRepository = tbCodeRepository; | |||
| this.tBCodeMapper = tBCodeMapper; | |||
| this.tBCodeSearchRepository = tBCodeSearchRepository; | |||
| @@ -60,4 +63,27 @@ public class TBCodeServiceImpl implements TBCodeService { | |||
| tbCodes = tbCodeRepository.saveAll(tbCodes); | |||
| return tbCodes.stream().map(tBCodeMapper::toDto).collect(Collectors.toList()); | |||
| } | |||
| @Override | |||
| @Transactional(readOnly = true) | |||
| public Optional<TBCodeDTO> findOne(Long id) { | |||
| log.debug("Request to get TBCode : {}", id); | |||
| return tbCodeRepository.findOneWithEagerRelationships(id) | |||
| .map(tBCodeMapper::toDto); | |||
| } | |||
| @Override | |||
| @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()); | |||
| } | |||
| TBCode tbCode = tBCodeMapper.toEntity(tbCodeDTO); | |||
| tbCode = tbCodeRepository.save(tbCode); | |||
| return Optional.ofNullable(tBCodeMapper.toDto(tbCode)); | |||
| } | |||
| } | |||
| @@ -1,9 +1,29 @@ | |||
| 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.TBCodeDetailsDTO; | |||
| @Mapper(componentModel = "spring", uses = {}) | |||
| @Mapper(componentModel = "spring", uses = {TBDetailUserMapper.class}) | |||
| public interface TBCodeDetailsMapper extends EntityMapper<TBCodeDetailsDTO, TBCodeDetails> { | |||
| @Mapping(source = "createdBy.id", target = "createdById") | |||
| @Mapping(source = "modifiedBy.id", target = "modifiedById") | |||
| @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); | |||
| default TBCodeDetails fromId(Long id) { | |||
| if (id == null) { | |||
| return null; | |||
| } | |||
| TBCodeDetails tBCodeDetails = new TBCodeDetails(); | |||
| tBCodeDetails.setId(id); | |||
| return tBCodeDetails; | |||
| } | |||
| } | |||
| @@ -1,10 +1,30 @@ | |||
| package vn.azteam.tpf.service.mapper; | |||
| import org.mapstruct.Mapper; | |||
| import org.mapstruct.Mapping; | |||
| import vn.azteam.tpf.domain.TBCode; | |||
| import vn.azteam.tpf.domain.TBCodeDetails; | |||
| import vn.azteam.tpf.service.dto.TBCodeDTO; | |||
| @Mapper(componentModel = "spring", uses = {}) | |||
| @Mapper(componentModel = "spring", uses = {TBDetailUserMapper.class}) | |||
| public interface TBCodeMapper extends EntityMapper<TBCodeDTO, TBCode> { | |||
| @Mapping(source = "createdBy.id", target = "createdById") | |||
| @Mapping(source = "modifiedBy.id", target = "modifiedById") | |||
| @Mapping(source = "deletedBy.id", target = "deletedById") | |||
| TBCodeDTO toDto(TBCode tbCode); | |||
| @Mapping(source = "tbCrop", target = "tbCrop") | |||
| @Mapping(source = "createdById", target = "createdBy") | |||
| @Mapping(source = "modifiedById", target = "modifiedBy") | |||
| @Mapping(source = "deletedById", target = "deletedBy") | |||
| TBCode toEntity(TBCodeDTO tBCodeDTO); | |||
| default TBCode fromId(Long id) { | |||
| if (id == null) { | |||
| return null; | |||
| } | |||
| TBCode tBCode = new TBCode(); | |||
| tBCode.setId(id); | |||
| return tBCode; | |||
| } | |||
| } | |||
| @@ -1,7 +1,12 @@ | |||
| package vn.azteam.tpf.web.rest; | |||
| import com.codahale.metrics.annotation.Timed; | |||
| 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 vn.azteam.tpf.service.TBCodeDetailsQueryService; | |||
| @@ -30,4 +35,14 @@ public class TBCodeDetailsResource { | |||
| this.userRoleUtil = userRoleUtil; | |||
| this.pageableUtil = pageableUtil; | |||
| } | |||
| @GetMapping("/tb-codes-scan/{code}") | |||
| @Timed | |||
| public ResponseEntity<?> getTBCodeScan(@PathVariable String code) { | |||
| if (StringUtils.isBlank(code)) { | |||
| return (ResponseEntity<?>) ResponseEntity.badRequest(); | |||
| } | |||
| tBCodeDetailsService.updateNumberScan(code); | |||
| return ResponseEntity.ok().build(); | |||
| } | |||
| } | |||
| @@ -1,6 +1,7 @@ | |||
| package vn.azteam.tpf.web.rest; | |||
| import com.codahale.metrics.annotation.Timed; | |||
| import io.github.jhipster.web.util.ResponseUtil; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -68,7 +69,7 @@ public class TBCodeResource { | |||
| * @param criteria the criterias which the requested entities should match | |||
| * @return the ResponseEntity with status 200 (OK) and the list of tBCode in body | |||
| */ | |||
| @GetMapping("/tb-codes-dropdown-list") | |||
| @GetMapping("/tb-codes/dropdown-list") | |||
| @Timed | |||
| public ResponseEntity<List<TBCodeDTO>> getAllTBCodesForDropdown(TBCodeCriteria criteria) { | |||
| log.debug("REST request to get TBCodes by criteria: {}", criteria); | |||
| @@ -145,6 +146,7 @@ public class TBCodeResource { | |||
| tBCodeDTO.setCreatedDate(Instant.now()); | |||
| tBCodeDTO.setCreatedById(currentUser.getUserId()); | |||
| tBCodeDTO.setStatus(TBCodeStatusEnum.NEW); | |||
| tBCodeDTO.setExpiredDate(tBCodeCreationDTO.getExpiredDate()); | |||
| TBCodeDTO result = null; | |||
| Boolean hasViolationException = false; | |||
| do { | |||
| @@ -183,4 +185,48 @@ public class TBCodeResource { | |||
| throw new RuntimeException(); | |||
| } | |||
| } | |||
| @GetMapping("/tb-codes/{id}") | |||
| @Timed | |||
| public ResponseEntity<TBCodeDTO> getTBCodes(@PathVariable Long id) { | |||
| log.debug("REST request to get TBCode : {}", id); | |||
| Optional<TBCodeDTO> tBCropDTO = tBCodeService.findOne(id); | |||
| //@CUONGLT - Filter scope customer's data | |||
| // if (!userRoleUtil.currentUserHasPermissionByCropId(id)) { | |||
| // throw new BadRequestAlertException("1018", ENTITY_NAME, "1018"); | |||
| // } | |||
| return ResponseUtil.wrapOrNotFound(tBCropDTO); | |||
| } | |||
| /** | |||
| * Add or delete crop's person in charges | |||
| * | |||
| * @param cropPersonInChargeDTO | |||
| * @return | |||
| */ | |||
| @PutMapping("/tb-codes/update/{id}/status/{status}") | |||
| @Timed | |||
| public ResponseEntity<TBCodeDTO> updateTBCode(@PathVariable Long id, 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"); | |||
| } | |||
| try { | |||
| TBCodeStatusEnum.valueOf(status); | |||
| } catch (Exception exception) { | |||
| throw new BadRequestAlertException("1039", ENTITY_NAME, "1039"); | |||
| } | |||
| UserDTO currentUser = userService.getCurrentUserDTO().get(); | |||
| TBCodeDTO tbCodeDTO = new TBCodeDTO(); | |||
| tbCodeDTO.setId(id); | |||
| tbCodeDTO.setModifiedDate(Instant.now()); | |||
| tbCodeDTO.setModifiedById(currentUser.getId()); | |||
| tbCodeDTO.setStatus(TBCodeStatusEnum.valueOf(status)); | |||
| Optional<TBCodeDTO> tBCodeUpdated = tBCodeService.updateStatusTBCode(tbCodeDTO); | |||
| // if (null != tBCropDTO) { | |||
| // sendNotificationPersonInCharge(cropPersonInChargeDTO, listAssignmentPrev); | |||
| // } | |||
| return ResponseUtil.wrapOrNotFound(tBCodeUpdated); | |||
| } | |||
| } | |||
| @@ -39,6 +39,10 @@ | |||
| <constraints nullable="true" /> | |||
| </column> | |||
| <column name="last_updated_date" type="timestamp"> | |||
| <constraints nullable="true" /> | |||
| </column> | |||
| <column name="created_date" type="timestamp"> | |||
| <constraints nullable="true" /> | |||
| </column> | |||