| @@ -14,7 +14,7 @@ import java.time.Instant; | |||
| @Table(name = "tb_code_details") | |||
| @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) | |||
| @Document(indexName = "smf_tbcodedetails") | |||
| public class TBCodeDetails implements Serializable { | |||
| public class TBCodeDetails implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| @@ -1,9 +1,11 @@ | |||
| package vn.azteam.tpf.repository; | |||
| import org.springframework.data.repository.query.Param; | |||
| import vn.azteam.tpf.domain.TBActivityType; | |||
| import org.springframework.data.jpa.repository.*; | |||
| import org.springframework.stereotype.Repository; | |||
| import java.util.List; | |||
| import java.util.Optional; | |||
| @@ -14,4 +16,7 @@ import java.util.Optional; | |||
| @Repository | |||
| public interface TBActivityTypeRepository extends JpaRepository<TBActivityType, Long>, JpaSpecificationExecutor<TBActivityType> { | |||
| Optional<TBActivityType> getByName(String name); | |||
| @Query(value = "select tbt from TBActivityType tbt where tbt.isAfterHarvest = :isAfterHarvest") | |||
| List<TBActivityType> findByAfterHarvest(@Param("isAfterHarvest") Boolean isAfterHarvest); | |||
| } | |||
| @@ -14,4 +14,6 @@ public interface TBCodeRepository extends JpaRepository<TBCode, Long>, JpaSpecif | |||
| //@Query("select tb_crop from TBCrop tb_crop left join fetch tb_crop.tbDetailUsers where tb_crop.id =:id") | |||
| Optional<TBCode> findById(Long id); | |||
| Optional<TBCode> findByCode(String code); | |||
| } | |||
| @@ -1,17 +1,8 @@ | |||
| package vn.azteam.tpf.service; | |||
| import java.util.ArrayList; | |||
| import java.util.Arrays; | |||
| import java.util.List; | |||
| import java.util.stream.Collectors; | |||
| import javax.persistence.EntityManager; | |||
| import javax.persistence.Query; | |||
| import javax.persistence.criteria.JoinType; | |||
| import com.google.common.collect.Lists; | |||
| import io.github.jhipster.service.QueryService; | |||
| import io.github.jhipster.service.filter.InstantFilter; | |||
| import io.github.jhipster.service.filter.LongFilter; | |||
| import io.github.jhipster.service.filter.StringFilter; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -22,18 +13,27 @@ import org.springframework.data.jpa.domain.Specification; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Propagation; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import io.github.jhipster.service.QueryService; | |||
| import org.springframework.util.StringUtils; | |||
| import org.springframework.web.multipart.MultipartFile; | |||
| import vn.azteam.tpf.Constants.Constants; | |||
| import vn.azteam.tpf.domain.TBActivityType; | |||
| import vn.azteam.tpf.domain.*; // for static metamodels | |||
| import vn.azteam.tpf.domain.TBActivityType_; | |||
| import vn.azteam.tpf.domain.TBCustomer_; | |||
| import vn.azteam.tpf.domain.TBDetailUser_; | |||
| import vn.azteam.tpf.repository.TBActivityTypeRepository; | |||
| import vn.azteam.tpf.service.dto.*; | |||
| import vn.azteam.tpf.service.dto.TBActivityTypeCriteria; | |||
| import vn.azteam.tpf.service.dto.TBActivityTypeDTO; | |||
| import vn.azteam.tpf.service.dto.UserDTO; | |||
| import vn.azteam.tpf.service.mapper.TBActivityTypeMapper; | |||
| import javax.persistence.EntityManager; | |||
| import javax.persistence.Query; | |||
| import javax.persistence.criteria.JoinType; | |||
| import java.util.ArrayList; | |||
| import java.util.Arrays; | |||
| import java.util.List; | |||
| import java.util.stream.Collectors; | |||
| /** | |||
| * Service for executing complex queries for TBActivityType entities in the database. | |||
| * The main input is a {@link TBActivityTypeCriteria} which gets converted to {@link Specification}, | |||
| @@ -92,6 +92,7 @@ public class TBActivityTypeQueryService extends QueryService<TBActivityType> { | |||
| /** | |||
| * Return a {@link List} of {@link TBActivityTypeDTO} which matches the criteria from the database | |||
| * | |||
| * @param criteria The object which holds all the filters, which the entities should match. | |||
| * @return the matching entities. | |||
| */ | |||
| @@ -102,10 +103,17 @@ public class TBActivityTypeQueryService extends QueryService<TBActivityType> { | |||
| return tBActivityTypeMapper.toDto(tBActivityTypeRepository.findAll(specification)); | |||
| } | |||
| @Transactional(readOnly = true) | |||
| public List<TBActivityTypeDTO> findByAfterHarvestTrue() { | |||
| log.debug("find by findByAfterHarvestTrue"); | |||
| return tBActivityTypeMapper.toDto(tBActivityTypeRepository.findByAfterHarvest(Boolean.TRUE)); | |||
| } | |||
| /** | |||
| * Return a {@link Page} of {@link TBActivityTypeDTO} which matches the criteria from the database | |||
| * | |||
| * @param criteria The object which holds all the filters, which the entities should match. | |||
| * @param page The page, which should be returned. | |||
| * @param page The page, which should be returned. | |||
| * @return the matching entities. | |||
| */ | |||
| @Transactional(readOnly = true) | |||
| @@ -118,6 +126,7 @@ public class TBActivityTypeQueryService extends QueryService<TBActivityType> { | |||
| /** | |||
| * Return the number of matching entities in the database | |||
| * | |||
| * @param criteria The object which holds all the filters, which the entities should match. | |||
| * @return the number of matching entities. | |||
| */ | |||
| @@ -213,10 +222,10 @@ public class TBActivityTypeQueryService extends QueryService<TBActivityType> { | |||
| } | |||
| public TBActivityTypeDTO findActivityTypeByName(String name) { | |||
| List<TBActivityType>tbActivityTypes = tBActivityTypeRepository.findAll().stream() | |||
| List<TBActivityType> tbActivityTypes = tBActivityTypeRepository.findAll().stream() | |||
| .filter(x -> x.getName().equals(name)) | |||
| .collect(Collectors.toList()); | |||
| List<TBActivityTypeDTO>tbActivityTypesDTO = tBActivityTypeMapper.toDto(tbActivityTypes); | |||
| List<TBActivityTypeDTO> tbActivityTypesDTO = tBActivityTypeMapper.toDto(tbActivityTypes); | |||
| return tbActivityTypesDTO.size() == 0 ? null : tbActivityTypesDTO.get(0); | |||
| } | |||
| @@ -230,8 +239,8 @@ public class TBActivityTypeQueryService extends QueryService<TBActivityType> { | |||
| } | |||
| public TBActivityTypeDTO updateUploadedFiles(TBActivityTypeDTO tBActivityTypeDTO, | |||
| MultipartFile[] images, | |||
| String deletedImage) { | |||
| MultipartFile[] images, | |||
| String deletedImage) { | |||
| if (deletedImage != null && deletedImage != Constants.EMPTY) { | |||
| this.fileStorageService.removeFile("url_logo", deletedImage); | |||
| } | |||
| @@ -266,7 +275,7 @@ public class TBActivityTypeQueryService extends QueryService<TBActivityType> { | |||
| " from tb_activity_type as at\n" + | |||
| " where at.deleted_date IS NULL "; | |||
| if(query != null && !query.isEmpty()) { | |||
| if (query != null && !query.isEmpty()) { | |||
| sqlString = sqlString + " and ( at.description like '%" + query + "%')\n"; | |||
| } | |||
| @@ -274,7 +283,7 @@ public class TBActivityTypeQueryService extends QueryService<TBActivityType> { | |||
| List<TBActivityTypeDTO> tbActivityTypeDTOs = tBActivityTypeMapper.toDto(tbActivityTypeQuery.getResultList()); | |||
| int start = Math.toIntExact(pageable.getOffset()); | |||
| int end = Math.toIntExact((start + pageable.getPageSize()) > tbActivityTypeDTOs.size() ? tbActivityTypeDTOs.size() : (start + pageable.getPageSize())); | |||
| if(tbActivityTypeDTOs.size() > start) { | |||
| if (tbActivityTypeDTOs.size() > start) { | |||
| return new PageImpl<>(tbActivityTypeDTOs.subList(start, end), pageable, tbActivityTypeDTOs.size()); | |||
| } | |||
| return new PageImpl<>(Lists.newArrayList(), pageable, tbActivityTypeDTOs.size()); | |||
| @@ -1,8 +1,8 @@ | |||
| package vn.azteam.tpf.service; | |||
| import vn.azteam.tpf.service.dto.TBCodeDetailsAndActivityDTO; | |||
| import vn.azteam.tpf.service.dto.TBCodeDetailsCreationDTO; | |||
| import vn.azteam.tpf.service.dto.TBCodeDetailsDTO; | |||
| import vn.azteam.tpf.service.dto.TBCropDetailDTOV2; | |||
| import vn.azteam.tpf.web.rest.errors.BadRequestAlertException; | |||
| import java.util.List; | |||
| @@ -17,7 +17,7 @@ public interface TBCodeDetailsService { | |||
| List<TBCodeDetailsDTO> saveAll(List<TBCodeDetailsCreationDTO> tBCodeDetailsDTOs); | |||
| TBCropDetailDTOV2 updateNumberScan(String code) throws BadRequestAlertException; | |||
| TBCodeDetailsAndActivityDTO updateNumberScan(String code) throws BadRequestAlertException; | |||
| Optional<TBCodeDetailsDTO> updateStatusTBCodeDetails(TBCodeDetailsDTO tBCodeDetailsDTO); | |||
| } | |||
| @@ -1,10 +1,7 @@ | |||
| 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 vn.azteam.tpf.service.dto.TBCodeDTO; | |||
| import java.util.List; | |||
| import java.util.Optional; | |||
| @@ -0,0 +1,53 @@ | |||
| package vn.azteam.tpf.service.dto; | |||
| import java.io.Serializable; | |||
| import java.time.Instant; | |||
| public class ActivityCodeCreationDTO implements Serializable { | |||
| private Long tbCropId; | |||
| private Long activityTypeId; | |||
| private Instant executeDate; | |||
| private String description; | |||
| private String location; | |||
| public Long getTbCropId() { | |||
| return tbCropId; | |||
| } | |||
| public void setTbCropId(Long tbCropId) { | |||
| this.tbCropId = tbCropId; | |||
| } | |||
| public Long getActivityTypeId() { | |||
| return activityTypeId; | |||
| } | |||
| public void setActivityTypeId(Long activityTypeId) { | |||
| this.activityTypeId = activityTypeId; | |||
| } | |||
| public Instant getExecuteDate() { | |||
| return executeDate; | |||
| } | |||
| public void setExecuteDate(Instant executeDate) { | |||
| this.executeDate = executeDate; | |||
| } | |||
| public String getDescription() { | |||
| return description; | |||
| } | |||
| public void setDescription(String description) { | |||
| this.description = description; | |||
| } | |||
| public String getLocation() { | |||
| return location; | |||
| } | |||
| public void setLocation(String location) { | |||
| this.location = location; | |||
| } | |||
| } | |||
| @@ -1,7 +1,7 @@ | |||
| package vn.azteam.tpf.service.dto; | |||
| import java.time.Instant; | |||
| import java.io.Serializable; | |||
| import java.time.Instant; | |||
| import java.util.Objects; | |||
| /** | |||
| @@ -47,6 +47,8 @@ public class TBActivityDTO implements Serializable { | |||
| private String activityTypeDescription; | |||
| private Boolean isAfterHarvest = Boolean.FALSE; | |||
| public Long getId() { | |||
| return id; | |||
| } | |||
| @@ -199,6 +201,14 @@ public class TBActivityDTO implements Serializable { | |||
| this.activityTypeDescription = activityTypeDescription; | |||
| } | |||
| public Boolean getAfterHarvest() { | |||
| return isAfterHarvest; | |||
| } | |||
| public void setAfterHarvest(Boolean afterHarvest) { | |||
| isAfterHarvest = afterHarvest; | |||
| } | |||
| @Override | |||
| public boolean equals(Object o) { | |||
| if (this == o) { | |||
| @@ -0,0 +1,58 @@ | |||
| package vn.azteam.tpf.service.dto; | |||
| import java.io.Serializable; | |||
| import java.util.List; | |||
| public class TBCodeDetailsAndActivityDTO implements Serializable { | |||
| private String description; | |||
| private TBCodeDetailsDTO tbCodeDetailsDTO; | |||
| private TBCropDTO tbCropDTO; | |||
| // Use for web only | |||
| private ActivityTimelineDTO activityTimeline; | |||
| // Use for app only | |||
| private List<TBActivityDTO> activities; | |||
| public TBCodeDetailsDTO getTbCodeDetailsDTO() { | |||
| return tbCodeDetailsDTO; | |||
| } | |||
| public void setTbCodeDetailsDTO(TBCodeDetailsDTO tbCodeDetailsDTO) { | |||
| this.tbCodeDetailsDTO = tbCodeDetailsDTO; | |||
| } | |||
| public TBCropDTO getTbCropDTO() { | |||
| return tbCropDTO; | |||
| } | |||
| public void setTbCropDTO(TBCropDTO tbCropDTO) { | |||
| this.tbCropDTO = tbCropDTO; | |||
| } | |||
| public ActivityTimelineDTO getActivityTimeline() { | |||
| return activityTimeline; | |||
| } | |||
| public void setActivityTimeline(ActivityTimelineDTO activityTimeline) { | |||
| this.activityTimeline = activityTimeline; | |||
| } | |||
| public List<TBActivityDTO> getActivities() { | |||
| return activities; | |||
| } | |||
| public void setActivities(List<TBActivityDTO> activities) { | |||
| this.activities = activities; | |||
| } | |||
| public String getDescription() { | |||
| return description; | |||
| } | |||
| public void setDescription(String description) { | |||
| this.description = description; | |||
| } | |||
| } | |||
| @@ -1,113 +0,0 @@ | |||
| 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; | |||
| } | |||
| } | |||
| @@ -26,8 +26,6 @@ import java.util.List; | |||
| import java.util.Optional; | |||
| import java.util.stream.Collectors; | |||
| import static vn.azteam.tpf.Constants.Constants.*; | |||
| /** | |||
| * Service Implementation for managing TBCodeDetails. | |||
| */ | |||
| @@ -47,8 +45,6 @@ public class TBCodeDetailsImpl implements TBCodeDetailsService { | |||
| private final UserService userService; | |||
| private final TBObjectUpdateService tbObjectUpdateService; | |||
| private final UserRoleUtil userRoleUtil; | |||
| private final TBActivityQueryService tBActivityQueryService; | |||
| @@ -65,17 +61,15 @@ public class TBCodeDetailsImpl implements TBCodeDetailsService { | |||
| TBCodeDetailsMapper tBCodeDetailsMapper, | |||
| TBDetailUserRepository tBDetailUserRepository, | |||
| UserService userService, | |||
| TBObjectUpdateService tbObjectUpdateService, | |||
| UserRoleUtil userRoleUtil, | |||
| TBActivityQueryService tBActivityQueryService, | |||
| TBCropService tbCropService, | |||
| TBCropQueryService tBCropQueryService, TBCropMapper tbCropMapper, | |||
| TBActivityQueryService tBActivityQueryService, TBCropService tbCropService, | |||
| TBCropQueryService tBCropQueryService, | |||
| TBCropMapper tbCropMapper, | |||
| TBCodeDetailsSearchRepository tBCodeDetailsSearchRepository) { | |||
| this.tbCodeDetailsRepository = tbCodeDetailsRepository; | |||
| this.tBCodeDetailsMapper = tBCodeDetailsMapper; | |||
| this.tBDetailUserRepository = tBDetailUserRepository; | |||
| this.userService = userService; | |||
| this.tbObjectUpdateService = tbObjectUpdateService; | |||
| this.userRoleUtil = userRoleUtil; | |||
| this.tBActivityQueryService = tBActivityQueryService; | |||
| this.tbCropService = tbCropService; | |||
| @@ -109,7 +103,7 @@ public class TBCodeDetailsImpl implements TBCodeDetailsService { | |||
| } | |||
| @Transactional | |||
| public TBCropDetailDTOV2 updateNumberScan(String code) throws BadRequestAlertException { | |||
| public TBCodeDetailsAndActivityDTO updateNumberScan(String code) throws BadRequestAlertException { | |||
| Optional<TBCodeDetails> tbCodeDetailsOptional = tbCodeDetailsRepository.findByCode(code); | |||
| if (tbCodeDetailsOptional.isPresent()) { | |||
| TBCodeDetails tbCodeDetails = tbCodeDetailsOptional.get(); | |||
| @@ -122,15 +116,18 @@ public class TBCodeDetailsImpl implements TBCodeDetailsService { | |||
| Integer numberScan = tbCodeDetails.getNumberScan(); | |||
| tbCodeDetails.setNumberScan(numberScan.equals(0) ? 1 : numberScan + 1); | |||
| tbCodeDetails.setLastUpdatedDate(Instant.now()); | |||
| tbCodeDetailsRepository.save(tbCodeDetails); | |||
| tbCodeDetails = tbCodeDetailsRepository.save(tbCodeDetails); | |||
| log.debug("update number scan find by criteria code : {}", code); | |||
| return this.getCodeDetailDTOResponseEntity(tbCropMapper.toDto(tbCodeDetailsOptional.get().getTbCode().getTbCrop()), Pageable.unpaged(), true); | |||
| TBCodeDetailsAndActivityDTO tbCodeDetailsAndActivityDTO = this.getCodeDetailDTOResponseEntity(tbCropMapper.toDto(tbCodeDetailsOptional.get().getTbCode().getTbCrop()), Pageable.unpaged(), true); | |||
| tbCodeDetailsAndActivityDTO.setTbCodeDetailsDTO(tBCodeDetailsMapper.toDto(tbCodeDetails)); | |||
| tbCodeDetailsAndActivityDTO.setDescription(tbCode.getDescription()); | |||
| return tbCodeDetailsAndActivityDTO; | |||
| } else { | |||
| throw new BadRequestAlertException("Scan code not found", "tb code details with code:", code); | |||
| } | |||
| } | |||
| private TBCropDetailDTOV2 getCodeDetailDTOResponseEntity( | |||
| private TBCodeDetailsAndActivityDTO getCodeDetailDTOResponseEntity( | |||
| TBCropDTO tBCropDTO, | |||
| Pageable pageable, | |||
| Boolean isRequestedFromWeb) { | |||
| @@ -139,77 +136,89 @@ public class TBCodeDetailsImpl implements TBCodeDetailsService { | |||
| throw new BadRequestAlertException("1018", ENTITY_NAME, "1018"); | |||
| } | |||
| Optional<UserDTO> currentUser = userService.getCurrentUserDTO(); | |||
| TBCropDetailDTOV2 tbCropDetailDTO = new TBCropDetailDTOV2(); | |||
| tbCropDetailDTO.setTbCropDTO(tBCropDTO); | |||
| TBCodeDetailsAndActivityDTO tbCodeDetailsAndActivityDTO = new TBCodeDetailsAndActivityDTO(); | |||
| tbCodeDetailsAndActivityDTO.setTbCropDTO(tBCropDTO); | |||
| // Get list of activity | |||
| TBActivityCriteria criteria = new TBActivityCriteria(); | |||
| LongFilter cropFilter = new LongFilter(); | |||
| cropFilter.setEquals(tBCropDTO.getId()); | |||
| criteria.setCropId(cropFilter); | |||
| // List<TBActivityTypeDTO> activityTypeDTOS = tBActivityTypeQueryService.findByAfterHarvestTrue(); | |||
| // List<Long> ids = activityTypeDTOS.stream().map(TBActivityTypeDTO::getId).collect(Collectors.toList()) | |||
| List<TBActivityDTO> allActivities = tBActivityQueryService.findByCriteria(criteria).stream() | |||
| .sorted(Comparator.comparing( | |||
| TBActivityDTO::getExecuteDate, | |||
| Comparator.nullsLast(Comparator.naturalOrder())).reversed()) | |||
| .collect(Collectors.toList()); | |||
| if (!allActivities.isEmpty()) { | |||
| allActivities = allActivities.stream() | |||
| .filter(tbActivityDTO -> tbActivityDTO.getAfterHarvest().equals(Boolean.TRUE)) | |||
| .collect(Collectors.toList()); | |||
| } | |||
| //remove env activities automatically | |||
| allActivities | |||
| .removeIf(activity -> ACTIVE_TYPE_UPDATE_ENV.equals(activity.getActivityTypeName()) | |||
| && activity.getCreatedById() == null); | |||
| // allActivities | |||
| // .removeIf(activity -> ACTIVE_TYPE_UPDATE_ENV.equals(activity.getActivityTypeName()) | |||
| // && activity.getCreatedById() == null); | |||
| // allActivities.removeIf(activity -> ACTIVE_TYPE_UPDATE_ENV.equals(activity.getActivityTypeId()) | |||
| // && 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())); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| } | |||
| // 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); | |||
| } | |||
| }); | |||
| } | |||
| } | |||
| // 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) { | |||
| @@ -219,23 +228,23 @@ public class TBCodeDetailsImpl implements TBCodeDetailsService { | |||
| if (isRequestedFromWeb) { | |||
| ActivityTimelineDTO activityTimeline = | |||
| tBCropQueryService.getActivityTimeline(tBCropDTO.getId(), allActivities, pageable); | |||
| tbCropDetailDTO.setActivityTimeline(activityTimeline); | |||
| tbCodeDetailsAndActivityDTO.setActivityTimeline(activityTimeline); | |||
| } else { | |||
| //allActivities = pageableUtil.changeTBActivityDTOToPageFromList(allActivities, pageable).getContent(); | |||
| tbCropDetailDTO.setActivities(allActivities); | |||
| tbCodeDetailsAndActivityDTO.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; | |||
| // 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 tbCodeDetailsAndActivityDTO; | |||
| } | |||
| @Override | |||
| @@ -2,20 +2,17 @@ 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.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.http.ResponseEntity; | |||
| 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.TBCodeDetailsAndActivityDTO; | |||
| 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.util.PageableUtil; | |||
| import vn.azteam.tpf.service.util.UserRoleUtil; | |||
| import vn.azteam.tpf.web.rest.errors.BadRequestAlertException; | |||
| import java.time.Instant; | |||
| @@ -39,12 +36,12 @@ public class TBCodeDetailsResource { | |||
| } | |||
| @GetMapping("/tb-code-details/scan/{code}") | |||
| public ResponseEntity<TBCropDetailDTOV2> getTBCodeDetailsScan(@PathVariable String code) { | |||
| public ResponseEntity<TBCodeDetailsAndActivityDTO> getTBCodeDetailsScan(@PathVariable String code) { | |||
| if (StringUtils.isBlank(code)) { | |||
| return (ResponseEntity<TBCropDetailDTOV2>) ResponseEntity.badRequest(); | |||
| return (ResponseEntity<TBCodeDetailsAndActivityDTO>) ResponseEntity.badRequest(); | |||
| } | |||
| TBCropDetailDTOV2 tbCropDetailDTOV2ResponseEntity = tBCodeDetailsService.updateNumberScan(code); | |||
| return ResponseEntity.ok().headers(null).body(tbCropDetailDTOV2ResponseEntity); | |||
| TBCodeDetailsAndActivityDTO tbCodeDetailsAndActivityDTO = tBCodeDetailsService.updateNumberScan(code); | |||
| return ResponseEntity.ok().headers(null).body(tbCodeDetailsAndActivityDTO); | |||
| } | |||
| @@ -20,6 +20,7 @@ import vn.azteam.tpf.web.rest.util.HeaderUtil; | |||
| import vn.azteam.tpf.web.rest.util.PaginationUtil; | |||
| import vn.azteam.tpf.web.rest.util.RandomStringUtil; | |||
| import java.io.IOException; | |||
| import java.net.URI; | |||
| import java.net.URISyntaxException; | |||
| import java.time.Instant; | |||
| @@ -38,7 +39,9 @@ public class TBCodeResource { | |||
| private final TBCodeService tBCodeService; | |||
| private final TBCodeDetailsService tbCodeDetailsService; | |||
| private final TBActivityTypeService tBActivityTypeService; | |||
| private final TBActivityService tBActivityService; | |||
| private final TBCropService tBCropService; | |||
| @@ -50,9 +53,13 @@ public class TBCodeResource { | |||
| private final PageableUtil pageableUtil; | |||
| public TBCodeResource(TBCodeService tBCodeService, TBCodeDetailsService tbCodeDetailsService, TBCropService tBCropService, UserService userService, TBCodeQueryService tBCodeQueryService, UserRoleUtil userRoleUtil, PageableUtil pageableUtil) { | |||
| public TBCodeResource(TBCodeService tBCodeService, TBActivityTypeService tBActivityTypeService, | |||
| TBActivityService tBActivityService, TBCropService tBCropService, UserService userService, | |||
| TBCodeQueryService tBCodeQueryService, | |||
| UserRoleUtil userRoleUtil, PageableUtil pageableUtil) { | |||
| this.tBCodeService = tBCodeService; | |||
| this.tbCodeDetailsService = tbCodeDetailsService; | |||
| this.tBActivityTypeService = tBActivityTypeService; | |||
| this.tBActivityService = tBActivityService; | |||
| this.tBCropService = tBCropService; | |||
| this.userService = userService; | |||
| this.tBCodeQueryService = tBCodeQueryService; | |||
| @@ -189,6 +196,7 @@ public class TBCodeResource { | |||
| public ResponseEntity<TBCodeDTO> getTBCodes(@PathVariable Long id) { | |||
| log.debug("REST request to get TBCode : {}", id); | |||
| Optional<TBCodeDTO> tBCodeDTO = tBCodeService.findOne(id); | |||
| // tra them thong tin hoat dong | |||
| //@CUONGLT - Filter scope customer's data | |||
| // if (!userRoleUtil.currentUserHasPermissionByCropId(tBCodeDTO.get().getId())) { | |||
| // throw new BadRequestAlertException("1018", ENTITY_NAME, "1018"); | |||
| @@ -196,6 +204,48 @@ public class TBCodeResource { | |||
| return ResponseUtil.wrapOrNotFound(tBCodeDTO); | |||
| } | |||
| // 1 api tạo hoạt động cho code | |||
| @PostMapping("/tb-codes/create/activity") | |||
| @Timed | |||
| public ResponseEntity<TBActivityDTO> createActivityForTBCode(@RequestBody ActivityCodeCreationDTO | |||
| activityCodeCreationDTO) throws IOException { | |||
| log.debug("REST request to save TBActivityDTO : {}", activityCodeCreationDTO); | |||
| //Set created by to current user login | |||
| UserDTO currentUser = userService.getCurrentUserDTO().get(); | |||
| if (activityCodeCreationDTO.getTbCropId() == null) { | |||
| throw new BadRequestAlertException("1047", ENTITY_NAME, "1047"); | |||
| } | |||
| if (activityCodeCreationDTO.getActivityTypeId() == null) { | |||
| throw new BadRequestAlertException("1047", ENTITY_NAME, "1047"); | |||
| } | |||
| if (activityCodeCreationDTO.getExecuteDate() == null) { | |||
| throw new BadRequestAlertException("1047", ENTITY_NAME, "1047"); | |||
| } | |||
| Optional<TBCropDTO> tBCropDTO = tBCropService.findOne(activityCodeCreationDTO.getTbCropId()); | |||
| if (!tBCropDTO.isPresent()) { | |||
| throw new BadRequestAlertException("1019", ENTITY_NAME, "1019"); | |||
| } | |||
| Optional<TBActivityTypeDTO> tbActivityTypeDTO = tBActivityTypeService.findOne(activityCodeCreationDTO.getActivityTypeId()); | |||
| if (!tbActivityTypeDTO.isPresent()) { | |||
| throw new BadRequestAlertException("1019", ENTITY_NAME, "1019"); | |||
| } | |||
| TBActivityDTO activityDTO = new TBActivityDTO(); | |||
| activityDTO.setCreatedById(currentUser.getId()); | |||
| activityDTO.setActivityTypeId(activityCodeCreationDTO.getActivityTypeId()); | |||
| activityDTO.setDescription(activityCodeCreationDTO.getDescription()); | |||
| activityDTO.setExecuteDate(activityCodeCreationDTO.getExecuteDate()); | |||
| activityDTO.setCropId(activityCodeCreationDTO.getTbCropId()); | |||
| activityDTO.setCreatedDate(Instant.now()); | |||
| TBActivityDTO result = tBActivityService.save(activityDTO); | |||
| return ResponseEntity.badRequest() | |||
| .headers(HeaderUtil.createEntityUpdateAlert("TBActivity", "Created activity success!")) | |||
| .body(result); | |||
| } | |||
| /** | |||
| * Add or delete crop's person in charges | |||
| * | |||