Ver código fonte

Update-mail-and-update-source-code

new-feature
Viet.LeQ2 1 ano atrás
pai
commit
ffb567dc24
7 arquivos alterados com 293 adições e 27 exclusões
  1. +2
    -1
      src/main/java/vn/azteam/tpf/service/TBCodeDetailsService.java
  2. +113
    -0
      src/main/java/vn/azteam/tpf/service/dto/TBCropDetailDTOV2.java
  3. +149
    -4
      src/main/java/vn/azteam/tpf/service/impl/TBCodeDetailsImpl.java
  4. +8
    -6
      src/main/java/vn/azteam/tpf/web/rest/TBCodeDetailsResource.java
  5. +11
    -12
      src/main/java/vn/azteam/tpf/web/rest/TBCodeResource.java
  6. +6
    -2
      src/main/resources/config/application-dev.yml
  7. +4
    -2
      src/main/resources/config/application-prod.yml

+ 2
- 1
src/main/java/vn/azteam/tpf/service/TBCodeDetailsService.java Ver arquivo

@@ -2,6 +2,7 @@ package vn.azteam.tpf.service;

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;
@@ -16,7 +17,7 @@ public interface TBCodeDetailsService {

List<TBCodeDetailsDTO> saveAll(List<TBCodeDetailsCreationDTO> tBCodeDetailsDTOs);

void updateNumberScan(String code) throws BadRequestAlertException;
TBCropDetailDTOV2 updateNumberScan(String code) throws BadRequestAlertException;

Optional<TBCodeDetailsDTO> updateStatusTBCodeDetails(TBCodeDetailsDTO tBCodeDetailsDTO);
}

+ 113
- 0
src/main/java/vn/azteam/tpf/service/dto/TBCropDetailDTOV2.java Ver arquivo

@@ -0,0 +1,113 @@
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;
}
}

+ 149
- 4
src/main/java/vn/azteam/tpf/service/impl/TBCodeDetailsImpl.java Ver arquivo

@@ -1,7 +1,9 @@
package vn.azteam.tpf.service.impl;

import io.github.jhipster.service.filter.LongFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vn.azteam.tpf.domain.TBCode;
@@ -10,18 +12,22 @@ 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.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.TBCropMapper;
import vn.azteam.tpf.service.util.UserRoleUtil;
import vn.azteam.tpf.web.rest.errors.BadRequestAlertException;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Comparator;
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.
*/
@@ -31,21 +37,50 @@ import java.util.stream.Collectors;
public class TBCodeDetailsImpl implements TBCodeDetailsService {
private final Logger log = LoggerFactory.getLogger(TBCodeDetailsImpl.class);

private static final String ENTITY_NAME = "tBCrop";

private final TBCodeDetailsRepository tbCodeDetailsRepository;

private final TBCodeDetailsMapper tBCodeDetailsMapper;

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;

public TBCodeDetailsImpl(TBCodeDetailsRepository tbCodeDetailsRepository,
TBCodeDetailsMapper tBCodeDetailsMapper,
TBDetailUserRepository tBDetailUserRepository,
UserService userService,
TBObjectUpdateService tbObjectUpdateService,
UserRoleUtil userRoleUtil,
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;
this.tBCropQueryService = tBCropQueryService;
this.tbCropMapper = tbCropMapper;
this.tBCodeDetailsSearchRepository = tBCodeDetailsSearchRepository;
}

@@ -74,7 +109,7 @@ public class TBCodeDetailsImpl implements TBCodeDetailsService {
}

@Transactional
public void updateNumberScan(String code) throws BadRequestAlertException {
public TBCropDetailDTOV2 updateNumberScan(String code) throws BadRequestAlertException {
Optional<TBCodeDetails> tbCodeDetailsOptional = tbCodeDetailsRepository.findByCode(code);
if (tbCodeDetailsOptional.isPresent()) {
TBCodeDetails tbCodeDetails = tbCodeDetailsOptional.get();
@@ -88,10 +123,120 @@ public class TBCodeDetailsImpl implements TBCodeDetailsService {
tbCodeDetails.setNumberScan(numberScan.equals(0) ? 1 : numberScan + 1);
tbCodeDetails.setLastUpdatedDate(Instant.now());
tbCodeDetailsRepository.save(tbCodeDetails);
this.getCodeDetailDTOResponseEntity(tbCropMapper.toDto(tbCodeDetailsOptional.get().getTbCode().getTbCrop()), Pageable.unpaged(), true);
log.debug("update number scan find by criteria code : {}", code);
} else {
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

+ 8
- 6
src/main/java/vn/azteam/tpf/web/rest/TBCodeDetailsResource.java Ver arquivo

@@ -12,6 +12,7 @@ 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.TBCropDetailDTOV2;
import vn.azteam.tpf.service.dto.UserDTO;
import vn.azteam.tpf.service.util.PageableUtil;
import vn.azteam.tpf.service.util.UserRoleUtil;
@@ -48,18 +49,19 @@ public class TBCodeDetailsResource {
}

@GetMapping("/tb-code-details/scan/{code}")
@Timed
public ResponseEntity<?> getTBCodeDetailsScan(@PathVariable String code) {
public ResponseEntity<TBCropDetailDTOV2> getTBCodeDetailsScan(@PathVariable String 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}")
@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);
if (id == null || org.apache.commons.lang3.StringUtils.isBlank(status)) {
throw new BadRequestAlertException("1039", ENTITY_NAME, "1039");

+ 11
- 12
src/main/java/vn/azteam/tpf/web/rest/TBCodeResource.java Ver arquivo

@@ -23,7 +23,6 @@ import vn.azteam.tpf.web.rest.util.RandomStringUtil;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
@@ -76,8 +75,8 @@ public class TBCodeResource {

//Authorize get list crop by customer of current user
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(
TBCodeDTO::getCreatedDate,
Comparator.nullsFirst(Comparator.naturalOrder())).reversed())
@@ -91,18 +90,18 @@ public class TBCodeResource {
*
* @param pageable the pagination information
* @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")
@Timed
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());

//Authorize get list crop by customer of current user
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(
TBCodeDTO::getCreatedDate,
Comparator.nullsFirst(Comparator.naturalOrder())).reversed())
@@ -118,7 +117,7 @@ public class TBCodeResource {

@PostMapping("/tb-codes")
@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);
//Set created by to current user login
UserDTO currentUser = userService.getCurrentUserDTO().get();
@@ -189,12 +188,12 @@ public class TBCodeResource {
@Timed
public ResponseEntity<TBCodeDTO> getTBCodes(@PathVariable Long 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
// if (!userRoleUtil.currentUserHasPermissionByCropId(id)) {
// if (!userRoleUtil.currentUserHasPermissionByCropId(tBCodeDTO.get().getId())) {
// throw new BadRequestAlertException("1018", ENTITY_NAME, "1018");
// }
return ResponseUtil.wrapOrNotFound(tBCropDTO);
return ResponseUtil.wrapOrNotFound(tBCodeDTO);
}

/**
@@ -223,7 +222,7 @@ public class TBCodeResource {
tbCodeDTO.setStatus(TBCodeStatusEnum.valueOf(status));

Optional<TBCodeDTO> tBCodeUpdated = tBCodeService.updateStatusTBCode(tbCodeDTO);
// if (null != tBCropDTO) {
// if (null != TBCodeDTO) {
// sendNotificationPersonInCharge(cropPersonInChargeDTO, listAssignmentPrev);
// }
return ResponseUtil.wrapOrNotFound(tBCodeUpdated);

+ 6
- 2
src/main/resources/config/application-dev.yml Ver arquivo

@@ -133,8 +133,12 @@ jhipster:
token-validity-in-seconds: 604800
token-validity-in-seconds-for-remember-me: 2592000
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
jmx:
enabled: true

+ 4
- 2
src/main/resources/config/application-prod.yml Ver arquivo

@@ -55,10 +55,12 @@ spring:
liquibase:
contexts: prod
mail:
from: [email protected]
host: smtp.yandex.com
port: 587
username: [email protected]
password: az12345
username: [email protected]
password: @zteam123
base-url: https://tpf.aztrace.vn
properties:
mail:
smtp:

Carregando…
Cancelar
Salvar