| import vn.azteam.tpf.service.dto.TBCodeDetailsCreationDTO; | import vn.azteam.tpf.service.dto.TBCodeDetailsCreationDTO; | ||||
| import vn.azteam.tpf.service.dto.TBCodeDetailsDTO; | import vn.azteam.tpf.service.dto.TBCodeDetailsDTO; | ||||
| import vn.azteam.tpf.service.dto.TBCropDetailDTOV2; | |||||
| import vn.azteam.tpf.web.rest.errors.BadRequestAlertException; | import vn.azteam.tpf.web.rest.errors.BadRequestAlertException; | ||||
| import java.util.List; | import java.util.List; | ||||
| List<TBCodeDetailsDTO> saveAll(List<TBCodeDetailsCreationDTO> tBCodeDetailsDTOs); | List<TBCodeDetailsDTO> saveAll(List<TBCodeDetailsCreationDTO> tBCodeDetailsDTOs); | ||||
| void updateNumberScan(String code) throws BadRequestAlertException; | |||||
| TBCropDetailDTOV2 updateNumberScan(String code) throws BadRequestAlertException; | |||||
| Optional<TBCodeDetailsDTO> updateStatusTBCodeDetails(TBCodeDetailsDTO tBCodeDetailsDTO); | Optional<TBCodeDetailsDTO> updateStatusTBCodeDetails(TBCodeDetailsDTO tBCodeDetailsDTO); | ||||
| } | } |
| package vn.azteam.tpf.service.dto; | |||||
| import java.io.Serializable; | |||||
| import java.time.Instant; | |||||
| import java.util.List; | |||||
| /** | |||||
| * A DTO for the TBCrop entity. | |||||
| */ | |||||
| public class TBCropDetailDTOV2 implements Serializable { | |||||
| private TBCropDTO tbCropDTO; | |||||
| // Use for web only | |||||
| private ActivityTimelineDTO activityTimeline; | |||||
| // Use for app only | |||||
| private List<TBActivityDTO> activities; | |||||
| private Instant plantingDate; | |||||
| private Instant sowingDate; | |||||
| private Double seedIncubationTime; | |||||
| private Integer numberPlants; | |||||
| private Integer numberCurrentPlants; | |||||
| private Instant endOfFarmingDate; | |||||
| private TBAddressDTO tbAddressDTO; | |||||
| public TBCropDTO getTbCropDTO() { | |||||
| return tbCropDTO; | |||||
| } | |||||
| public void setTbCropDTO(TBCropDTO tbCropDTO) { | |||||
| this.tbCropDTO = tbCropDTO; | |||||
| } | |||||
| public Instant getSowingDate() { | |||||
| return sowingDate; | |||||
| } | |||||
| public void setSowingDate(Instant sowingDate) { | |||||
| this.sowingDate = sowingDate; | |||||
| } | |||||
| public Instant getPlantingDate() { | |||||
| return plantingDate; | |||||
| } | |||||
| public void setPlantingDate(Instant plantingDate) { | |||||
| this.plantingDate = plantingDate; | |||||
| } | |||||
| public Double getSeedIncubationTime() { | |||||
| return seedIncubationTime; | |||||
| } | |||||
| public void setSeedIncubationTime(Double seedIncubationTime) { | |||||
| this.seedIncubationTime = seedIncubationTime; | |||||
| } | |||||
| public Integer getNumberPlants() { | |||||
| return numberPlants; | |||||
| } | |||||
| public void setNumberPlants(Integer numberPlants) { | |||||
| this.numberPlants = numberPlants; | |||||
| } | |||||
| public Integer getNumberCurrentPlants() { | |||||
| return numberCurrentPlants; | |||||
| } | |||||
| public void setNumberCurrentPlants(Integer numberCurrentPlants) { | |||||
| this.numberCurrentPlants = numberCurrentPlants; | |||||
| } | |||||
| public Instant getEndOfFarmingDate() { | |||||
| return endOfFarmingDate; | |||||
| } | |||||
| public void setEndOfFarmingDate(Instant endOfFarmingDate) { | |||||
| this.endOfFarmingDate = endOfFarmingDate; | |||||
| } | |||||
| public List<TBActivityDTO> getActivities() { | |||||
| return activities; | |||||
| } | |||||
| public void setActivities(List<TBActivityDTO> activities) { | |||||
| this.activities = activities; | |||||
| } | |||||
| public ActivityTimelineDTO getActivityTimeline() { | |||||
| return activityTimeline; | |||||
| } | |||||
| public void setActivityTimeline(ActivityTimelineDTO activityTimeline) { | |||||
| this.activityTimeline = activityTimeline; | |||||
| } | |||||
| public TBAddressDTO getTbAddressDTO() { | |||||
| return tbAddressDTO; | |||||
| } | |||||
| public void setTbAddressDTO(TBAddressDTO tbAddressDTO) { | |||||
| this.tbAddressDTO = tbAddressDTO; | |||||
| } | |||||
| } |
| package vn.azteam.tpf.service.impl; | package vn.azteam.tpf.service.impl; | ||||
| import io.github.jhipster.service.filter.LongFilter; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.data.domain.Pageable; | |||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import org.springframework.transaction.annotation.Transactional; | import org.springframework.transaction.annotation.Transactional; | ||||
| import vn.azteam.tpf.domain.TBCode; | import vn.azteam.tpf.domain.TBCode; | ||||
| import vn.azteam.tpf.repository.TBCodeDetailsRepository; | import vn.azteam.tpf.repository.TBCodeDetailsRepository; | ||||
| import vn.azteam.tpf.repository.TBDetailUserRepository; | import vn.azteam.tpf.repository.TBDetailUserRepository; | ||||
| import vn.azteam.tpf.repository.search.TBCodeDetailsSearchRepository; | 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.*; | |||||
| import vn.azteam.tpf.service.dto.*; | |||||
| import vn.azteam.tpf.service.mapper.TBCodeDetailsMapper; | import vn.azteam.tpf.service.mapper.TBCodeDetailsMapper; | ||||
| import vn.azteam.tpf.service.mapper.TBCropMapper; | |||||
| import vn.azteam.tpf.service.util.UserRoleUtil; | |||||
| import vn.azteam.tpf.web.rest.errors.BadRequestAlertException; | import vn.azteam.tpf.web.rest.errors.BadRequestAlertException; | ||||
| import java.time.Instant; | import java.time.Instant; | ||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.Comparator; | |||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Optional; | import java.util.Optional; | ||||
| import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||
| import static vn.azteam.tpf.Constants.Constants.*; | |||||
| /** | /** | ||||
| * Service Implementation for managing TBCodeDetails. | * Service Implementation for managing TBCodeDetails. | ||||
| */ | */ | ||||
| public class TBCodeDetailsImpl implements TBCodeDetailsService { | public class TBCodeDetailsImpl implements TBCodeDetailsService { | ||||
| private final Logger log = LoggerFactory.getLogger(TBCodeDetailsImpl.class); | private final Logger log = LoggerFactory.getLogger(TBCodeDetailsImpl.class); | ||||
| private static final String ENTITY_NAME = "tBCrop"; | |||||
| private final TBCodeDetailsRepository tbCodeDetailsRepository; | private final TBCodeDetailsRepository tbCodeDetailsRepository; | ||||
| private final TBCodeDetailsMapper tBCodeDetailsMapper; | private final TBCodeDetailsMapper tBCodeDetailsMapper; | ||||
| private final TBDetailUserRepository tBDetailUserRepository; | private final TBDetailUserRepository tBDetailUserRepository; | ||||
| private final UserService userService; | |||||
| private final TBObjectUpdateService tbObjectUpdateService; | |||||
| private final UserRoleUtil userRoleUtil; | |||||
| private final TBActivityQueryService tBActivityQueryService; | |||||
| private final TBCropService tbCropService; | |||||
| private final TBCropQueryService tBCropQueryService; | |||||
| private final TBCropMapper tbCropMapper; | |||||
| private final TBCodeDetailsSearchRepository tBCodeDetailsSearchRepository; | private final TBCodeDetailsSearchRepository tBCodeDetailsSearchRepository; | ||||
| public TBCodeDetailsImpl(TBCodeDetailsRepository tbCodeDetailsRepository, | public TBCodeDetailsImpl(TBCodeDetailsRepository tbCodeDetailsRepository, | ||||
| TBCodeDetailsMapper tBCodeDetailsMapper, | TBCodeDetailsMapper tBCodeDetailsMapper, | ||||
| TBDetailUserRepository tBDetailUserRepository, | TBDetailUserRepository tBDetailUserRepository, | ||||
| UserService userService, | |||||
| TBObjectUpdateService tbObjectUpdateService, | |||||
| UserRoleUtil userRoleUtil, | |||||
| TBActivityQueryService tBActivityQueryService, | |||||
| TBCropService tbCropService, | |||||
| TBCropQueryService tBCropQueryService, TBCropMapper tbCropMapper, | |||||
| TBCodeDetailsSearchRepository tBCodeDetailsSearchRepository) { | TBCodeDetailsSearchRepository tBCodeDetailsSearchRepository) { | ||||
| this.tbCodeDetailsRepository = tbCodeDetailsRepository; | this.tbCodeDetailsRepository = tbCodeDetailsRepository; | ||||
| this.tBCodeDetailsMapper = tBCodeDetailsMapper; | this.tBCodeDetailsMapper = tBCodeDetailsMapper; | ||||
| this.tBDetailUserRepository = tBDetailUserRepository; | this.tBDetailUserRepository = tBDetailUserRepository; | ||||
| this.userService = userService; | |||||
| this.tbObjectUpdateService = tbObjectUpdateService; | |||||
| this.userRoleUtil = userRoleUtil; | |||||
| this.tBActivityQueryService = tBActivityQueryService; | |||||
| this.tbCropService = tbCropService; | |||||
| this.tBCropQueryService = tBCropQueryService; | |||||
| this.tbCropMapper = tbCropMapper; | |||||
| this.tBCodeDetailsSearchRepository = tBCodeDetailsSearchRepository; | this.tBCodeDetailsSearchRepository = tBCodeDetailsSearchRepository; | ||||
| } | } | ||||
| } | } | ||||
| @Transactional | @Transactional | ||||
| public void updateNumberScan(String code) throws BadRequestAlertException { | |||||
| public TBCropDetailDTOV2 updateNumberScan(String code) throws BadRequestAlertException { | |||||
| Optional<TBCodeDetails> tbCodeDetailsOptional = tbCodeDetailsRepository.findByCode(code); | Optional<TBCodeDetails> tbCodeDetailsOptional = tbCodeDetailsRepository.findByCode(code); | ||||
| if (tbCodeDetailsOptional.isPresent()) { | if (tbCodeDetailsOptional.isPresent()) { | ||||
| TBCodeDetails tbCodeDetails = tbCodeDetailsOptional.get(); | TBCodeDetails tbCodeDetails = tbCodeDetailsOptional.get(); | ||||
| tbCodeDetails.setNumberScan(numberScan.equals(0) ? 1 : numberScan + 1); | tbCodeDetails.setNumberScan(numberScan.equals(0) ? 1 : numberScan + 1); | ||||
| tbCodeDetails.setLastUpdatedDate(Instant.now()); | tbCodeDetails.setLastUpdatedDate(Instant.now()); | ||||
| tbCodeDetailsRepository.save(tbCodeDetails); | tbCodeDetailsRepository.save(tbCodeDetails); | ||||
| this.getCodeDetailDTOResponseEntity(tbCropMapper.toDto(tbCodeDetailsOptional.get().getTbCode().getTbCrop()), Pageable.unpaged(), true); | |||||
| log.debug("update number scan find by criteria code : {}", code); | log.debug("update number scan find by criteria code : {}", code); | ||||
| } else { | } else { | ||||
| throw new BadRequestAlertException("Scan code not found", "tb code details with code:", code); | throw new BadRequestAlertException("Scan code not found", "tb code details with code:", code); | ||||
| } | } | ||||
| return null; | |||||
| } | |||||
| private TBCropDetailDTOV2 getCodeDetailDTOResponseEntity( | |||||
| TBCropDTO tBCropDTO, | |||||
| Pageable pageable, | |||||
| Boolean isRequestedFromWeb) { | |||||
| // Optional<TBCropDTO> tBCropDTO = tBCropService.findOne(id); | |||||
| if (!userRoleUtil.currentUserHasPermissionByCropId(tBCropDTO.getId())) { | |||||
| throw new BadRequestAlertException("1018", ENTITY_NAME, "1018"); | |||||
| } | |||||
| Optional<UserDTO> currentUser = userService.getCurrentUserDTO(); | |||||
| TBCropDetailDTOV2 tbCropDetailDTO = new TBCropDetailDTOV2(); | |||||
| tbCropDetailDTO.setTbCropDTO(tBCropDTO); | |||||
| // Get list of activity | |||||
| TBActivityCriteria criteria = new TBActivityCriteria(); | |||||
| LongFilter cropFilter = new LongFilter(); | |||||
| cropFilter.setEquals(tBCropDTO.getId()); | |||||
| criteria.setCropId(cropFilter); | |||||
| List<TBActivityDTO> allActivities = tBActivityQueryService.findByCriteria(criteria).stream() | |||||
| .sorted(Comparator.comparing( | |||||
| TBActivityDTO::getExecuteDate, | |||||
| Comparator.nullsLast(Comparator.naturalOrder())).reversed()) | |||||
| .collect(Collectors.toList()); | |||||
| //remove env activities automatically | |||||
| allActivities | |||||
| .removeIf(activity -> ACTIVE_TYPE_UPDATE_ENV.equals(activity.getActivityTypeName()) | |||||
| && activity.getCreatedById() == null); | |||||
| // Lo Uom | |||||
| if (tBCropDTO.getTbCropTypeId() == 1) { | |||||
| // Get sowing Date | |||||
| TBActivityDTO nurseryActivity = allActivities.stream() | |||||
| .sorted(Comparator.comparing( | |||||
| TBActivityDTO::getExecuteDate, | |||||
| Comparator.nullsLast(Comparator.naturalOrder()))) | |||||
| .filter(activity -> ACTIVE_TYPE_NURSERY.equals(activity.getActivityTypeName())) | |||||
| .findAny() | |||||
| .orElse(null); | |||||
| if (nurseryActivity != null) { | |||||
| tbCropDetailDTO.setSowingDate(nurseryActivity.getExecuteDate()); | |||||
| List<TBObjectUpdateDTO> tbObjectUpdateDTOs = tbObjectUpdateService.findByTBActivityId(nurseryActivity.getId(), | |||||
| Pageable.unpaged()); | |||||
| if (tbObjectUpdateDTOs != null && tbObjectUpdateDTOs.size() > 0) { | |||||
| tbObjectUpdateDTOs.forEach(item -> { | |||||
| if (item.getTbObjectParameterDTO().getName().equals(THOI_GIAN_NGAM_HAT)) { | |||||
| item.setIndex(item.getIndex() != null && !item.getIndex().isEmpty() ? item.getIndex() : "0"); | |||||
| tbCropDetailDTO.setSeedIncubationTime(Double.valueOf(item.getIndex())); | |||||
| } | |||||
| }); | |||||
| } | |||||
| } | |||||
| } | |||||
| //Lo Trong | |||||
| if (tBCropDTO.getTbCropTypeId() == 2) { | |||||
| // Get planting Date | |||||
| TBActivityDTO plantingActivity = allActivities.stream() | |||||
| .sorted(Comparator.comparing( | |||||
| TBActivityDTO::getExecuteDate, | |||||
| Comparator.nullsLast(Comparator.naturalOrder()))) | |||||
| .filter(activity -> ACTIVE_TYPE_PLANTING.equals(activity.getActivityTypeName())) | |||||
| .findAny() | |||||
| .orElse(null); | |||||
| tbCropDetailDTO.setPlantingDate(plantingActivity != null ? plantingActivity.getExecuteDate() : null); | |||||
| List<Long> listActivities = allActivities.stream().map(TBActivityDTO::getId).collect(Collectors.toList()); | |||||
| List<TBObjectUpdateDTO> tbObjectUpdateDTOs = tbObjectUpdateService.findByInListTBActivityId(listActivities, Pageable.unpaged()); | |||||
| if (tbObjectUpdateDTOs != null && tbObjectUpdateDTOs.size() > 0) { | |||||
| tbObjectUpdateDTOs.forEach(item -> { | |||||
| if (item.getTbObjectParameterDTO().getName().equals(SO_LUONG_CAY_TRONG)) { | |||||
| item.setIndex(item.getIndex() != null && !item.getIndex().isEmpty() ? item.getIndex() : "0"); | |||||
| tbCropDetailDTO.setNumberPlants(Integer.parseInt(item.getIndex().replaceAll("[^0-9]", ""))); | |||||
| tbCropDetailDTO.setNumberCurrentPlants(Integer.parseInt(item.getIndex().replaceAll("[^0-9]", ""))); | |||||
| } | |||||
| if (item.getTbObjectParameterDTO().getName().equals(SO_LUONG_LOAI_BO)) { | |||||
| item.setIndex(item.getIndex() != null && !item.getIndex().isEmpty() ? item.getIndex() : "0"); | |||||
| Integer currentNumberPlants = tbCropDetailDTO.getNumberPlants() - Integer.parseInt(item.getIndex().replaceAll("[^0-9]", "")); | |||||
| tbCropDetailDTO.setNumberCurrentPlants(currentNumberPlants > 0 ? currentNumberPlants : 0); | |||||
| } | |||||
| }); | |||||
| } | |||||
| } | |||||
| //Filter assignment croptype by customer | |||||
| if (currentUser.get().getCustomerId() != null) { | |||||
| List<Long> ListActivityTypeId = tbCropService.getListActivityTypeIdByByCustomerAndCropType(currentUser.get().getCustomerId(), tBCropDTO.getTbCropTypeId()); | |||||
| allActivities = allActivities.stream().filter(item -> ListActivityTypeId.contains(item.getActivityTypeId())).collect(Collectors.toList()); | |||||
| } | |||||
| if (isRequestedFromWeb) { | |||||
| ActivityTimelineDTO activityTimeline = | |||||
| tBCropQueryService.getActivityTimeline(tBCropDTO.getId(), allActivities, pageable); | |||||
| tbCropDetailDTO.setActivityTimeline(activityTimeline); | |||||
| } else { | |||||
| //allActivities = pageableUtil.changeTBActivityDTOToPageFromList(allActivities, pageable).getContent(); | |||||
| tbCropDetailDTO.setActivities(allActivities); | |||||
| } | |||||
| TBActivityDTO endActivity = allActivities.stream() | |||||
| .sorted(Comparator.comparing( | |||||
| TBActivityDTO::getExecuteDate, | |||||
| Comparator.nullsLast(Comparator.naturalOrder())).reversed()) | |||||
| .filter(activity -> ACTIVE_TYPE_END.equals(activity.getActivityTypeName())) | |||||
| .findAny() | |||||
| .orElse(null); | |||||
| if (endActivity != null) { | |||||
| tbCropDetailDTO.setEndOfFarmingDate(endActivity.getExecuteDate()); | |||||
| } | |||||
| return tbCropDetailDTO; | |||||
| } | } | ||||
| @Override | @Override |
| import vn.azteam.tpf.service.TBCodeDetailsService; | import vn.azteam.tpf.service.TBCodeDetailsService; | ||||
| import vn.azteam.tpf.service.UserService; | import vn.azteam.tpf.service.UserService; | ||||
| import vn.azteam.tpf.service.dto.TBCodeDetailsDTO; | import vn.azteam.tpf.service.dto.TBCodeDetailsDTO; | ||||
| import vn.azteam.tpf.service.dto.TBCropDetailDTOV2; | |||||
| import vn.azteam.tpf.service.dto.UserDTO; | 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; | ||||
| } | } | ||||
| @GetMapping("/tb-code-details/scan/{code}") | @GetMapping("/tb-code-details/scan/{code}") | ||||
| @Timed | |||||
| public ResponseEntity<?> getTBCodeDetailsScan(@PathVariable String code) { | |||||
| public ResponseEntity<TBCropDetailDTOV2> getTBCodeDetailsScan(@PathVariable String code) { | |||||
| if (StringUtils.isBlank(code)) { | if (StringUtils.isBlank(code)) { | ||||
| return (ResponseEntity<?>) ResponseEntity.badRequest(); | |||||
| return (ResponseEntity<TBCropDetailDTOV2>) ResponseEntity.badRequest(); | |||||
| } | } | ||||
| tBCodeDetailsService.updateNumberScan(code); | |||||
| return ResponseEntity.ok().build(); | |||||
| TBCropDetailDTOV2 tbCropDetailDTOV2ResponseEntity = tBCodeDetailsService.updateNumberScan(code); | |||||
| return ResponseEntity.ok().headers(null).body(tbCropDetailDTOV2ResponseEntity); | |||||
| } | } | ||||
| @PutMapping("/tb-code-details/update/{id}/status/{status}") | @PutMapping("/tb-code-details/update/{id}/status/{status}") | ||||
| @Timed | @Timed | ||||
| public ResponseEntity<TBCodeDetailsDTO> updateTBCodeDetailsStatus(@PathVariable Long id, @PathVariable String status) { | |||||
| public ResponseEntity<TBCodeDetailsDTO> updateTBCodeDetailsStatus(@PathVariable Long id, @PathVariable String | |||||
| status) { | |||||
| log.debug("REST request to update tb codes : {}, status {} ", id, status); | log.debug("REST request to update tb codes : {}, status {} ", id, status); | ||||
| if (id == null || org.apache.commons.lang3.StringUtils.isBlank(status)) { | if (id == null || org.apache.commons.lang3.StringUtils.isBlank(status)) { | ||||
| throw new BadRequestAlertException("1039", ENTITY_NAME, "1039"); | throw new BadRequestAlertException("1039", ENTITY_NAME, "1039"); |
| import java.net.URI; | import java.net.URI; | ||||
| import java.net.URISyntaxException; | import java.net.URISyntaxException; | ||||
| import java.time.Instant; | import java.time.Instant; | ||||
| import java.util.ArrayList; | |||||
| import java.util.Comparator; | import java.util.Comparator; | ||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Optional; | import java.util.Optional; | ||||
| //Authorize get list crop by customer of current user | //Authorize get list crop by customer of current user | ||||
| List<TBCodeDTO> result = page.getContent().stream() | List<TBCodeDTO> result = page.getContent().stream() | ||||
| .filter(item -> userRoleUtil.currentUserHasPermissionByCustomerId(item.getId()) | |||||
| && userRoleUtil.currentUserHasPermissionByCropId(item.getId())) | |||||
| .filter(item -> userRoleUtil.currentUserHasPermissionByCustomerId(item.getTbCrop().getId()) | |||||
| && userRoleUtil.currentUserHasPermissionByCropId(item.getTbCrop().getId())) | |||||
| .sorted(Comparator.comparing( | .sorted(Comparator.comparing( | ||||
| TBCodeDTO::getCreatedDate, | TBCodeDTO::getCreatedDate, | ||||
| Comparator.nullsFirst(Comparator.naturalOrder())).reversed()) | Comparator.nullsFirst(Comparator.naturalOrder())).reversed()) | ||||
| * | * | ||||
| * @param pageable the pagination information | * @param pageable the pagination information | ||||
| * @param criteria the criterias which the requested entities should match | * @param criteria the criterias which the requested entities should match | ||||
| * @return the ResponseEntity with status 200 (OK) and the list of tBCrops in body | |||||
| * @return the ResponseEntity with status 200 (OK) and the list of TBCodes in body | |||||
| */ | */ | ||||
| @GetMapping("/tb-codes") | @GetMapping("/tb-codes") | ||||
| @Timed | @Timed | ||||
| public ResponseEntity<List<TBCodeDTO>> getAllTBCodes(TBCodeCriteria criteria, Pageable pageable) { | public ResponseEntity<List<TBCodeDTO>> getAllTBCodes(TBCodeCriteria criteria, Pageable pageable) { | ||||
| log.debug("REST request to get TBCrops by criteria: {}", criteria); | |||||
| log.debug("REST request to get TBCodes by criteria: {}", criteria); | |||||
| Page<TBCodeDTO> page = tBCodeQueryService.findByCriteria(criteria, Pageable.unpaged()); | Page<TBCodeDTO> page = tBCodeQueryService.findByCriteria(criteria, Pageable.unpaged()); | ||||
| //Authorize get list crop by customer of current user | //Authorize get list crop by customer of current user | ||||
| List<TBCodeDTO> result = page.getContent().stream() | List<TBCodeDTO> result = page.getContent().stream() | ||||
| .filter(item -> userRoleUtil.currentUserHasPermissionByCustomerId(item.getId()) | |||||
| && userRoleUtil.currentUserHasPermissionByCropId(item.getId())) | |||||
| .filter(item -> userRoleUtil.currentUserHasPermissionByCustomerId(item.getTbCrop().getId()) | |||||
| && userRoleUtil.currentUserHasPermissionByCropId(item.getTbCrop().getId())) | |||||
| .sorted(Comparator.comparing( | .sorted(Comparator.comparing( | ||||
| TBCodeDTO::getCreatedDate, | TBCodeDTO::getCreatedDate, | ||||
| Comparator.nullsFirst(Comparator.naturalOrder())).reversed()) | Comparator.nullsFirst(Comparator.naturalOrder())).reversed()) | ||||
| @PostMapping("/tb-codes") | @PostMapping("/tb-codes") | ||||
| @Timed | @Timed | ||||
| public ResponseEntity<TBCodeDTO> createTBCrop(@RequestBody TBCodeCreationDTO tBCodeCreationDTO) throws URISyntaxException { | |||||
| public ResponseEntity<TBCodeDTO> createTBCode(@RequestBody TBCodeCreationDTO tBCodeCreationDTO) throws URISyntaxException { | |||||
| log.debug("REST request to save TBCode : {}", tBCodeCreationDTO); | log.debug("REST request to save TBCode : {}", tBCodeCreationDTO); | ||||
| //Set created by to current user login | //Set created by to current user login | ||||
| UserDTO currentUser = userService.getCurrentUserDTO().get(); | UserDTO currentUser = userService.getCurrentUserDTO().get(); | ||||
| @Timed | @Timed | ||||
| public ResponseEntity<TBCodeDTO> getTBCodes(@PathVariable Long id) { | public ResponseEntity<TBCodeDTO> getTBCodes(@PathVariable Long id) { | ||||
| log.debug("REST request to get TBCode : {}", id); | log.debug("REST request to get TBCode : {}", id); | ||||
| Optional<TBCodeDTO> tBCropDTO = tBCodeService.findOne(id); | |||||
| Optional<TBCodeDTO> tBCodeDTO = tBCodeService.findOne(id); | |||||
| //@CUONGLT - Filter scope customer's data | //@CUONGLT - Filter scope customer's data | ||||
| // if (!userRoleUtil.currentUserHasPermissionByCropId(id)) { | |||||
| // if (!userRoleUtil.currentUserHasPermissionByCropId(tBCodeDTO.get().getId())) { | |||||
| // throw new BadRequestAlertException("1018", ENTITY_NAME, "1018"); | // throw new BadRequestAlertException("1018", ENTITY_NAME, "1018"); | ||||
| // } | // } | ||||
| return ResponseUtil.wrapOrNotFound(tBCropDTO); | |||||
| return ResponseUtil.wrapOrNotFound(tBCodeDTO); | |||||
| } | } | ||||
| /** | /** | ||||
| tbCodeDTO.setStatus(TBCodeStatusEnum.valueOf(status)); | tbCodeDTO.setStatus(TBCodeStatusEnum.valueOf(status)); | ||||
| Optional<TBCodeDTO> tBCodeUpdated = tBCodeService.updateStatusTBCode(tbCodeDTO); | Optional<TBCodeDTO> tBCodeUpdated = tBCodeService.updateStatusTBCode(tbCodeDTO); | ||||
| // if (null != tBCropDTO) { | |||||
| // if (null != TBCodeDTO) { | |||||
| // sendNotificationPersonInCharge(cropPersonInChargeDTO, listAssignmentPrev); | // sendNotificationPersonInCharge(cropPersonInChargeDTO, listAssignmentPrev); | ||||
| // } | // } | ||||
| return ResponseUtil.wrapOrNotFound(tBCodeUpdated); | return ResponseUtil.wrapOrNotFound(tBCodeUpdated); |
| token-validity-in-seconds: 604800 | token-validity-in-seconds: 604800 | ||||
| token-validity-in-seconds-for-remember-me: 2592000 | token-validity-in-seconds-for-remember-me: 2592000 | ||||
| mail: # specific JHipster mail property, for standard properties see MailProperties | mail: # specific JHipster mail property, for standard properties see MailProperties | ||||
| from: [email protected] | |||||
| base-url: https://smf.aztrace.vn | |||||
| from: [email protected] | |||||
| host: smtp.yandex.com | |||||
| port: 587 | |||||
| username: [email protected] | |||||
| password: @zteam123 | |||||
| base-url: https://tpf.aztrace.vn | |||||
| metrics: # DropWizard Metrics configuration, used by MetricsConfiguration | metrics: # DropWizard Metrics configuration, used by MetricsConfiguration | ||||
| jmx: | jmx: | ||||
| enabled: true | enabled: true |
| liquibase: | liquibase: | ||||
| contexts: prod | contexts: prod | ||||
| mail: | mail: | ||||
| from: [email protected] | |||||
| host: smtp.yandex.com | host: smtp.yandex.com | ||||
| port: 587 | port: 587 | ||||
| username: [email protected] | |||||
| password: az12345 | |||||
| username: [email protected] | |||||
| password: @zteam123 | |||||
| base-url: https://tpf.aztrace.vn | |||||
| properties: | properties: | ||||
| mail: | mail: | ||||
| smtp: | smtp: |