| package vn.azteam.tpf.domain; | package vn.azteam.tpf.domain; | ||||
| import com.fasterxml.jackson.annotation.JsonIgnore; | |||||
| import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||||
| import org.hibernate.annotations.Cache; | import org.hibernate.annotations.Cache; | ||||
| import org.hibernate.annotations.CacheConcurrencyStrategy; | import org.hibernate.annotations.CacheConcurrencyStrategy; | ||||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | @GeneratedValue(strategy = GenerationType.IDENTITY) | ||||
| private Long id; | private Long id; | ||||
| @JsonIgnore | |||||
| @OneToOne | |||||
| @MapsId | |||||
| @JoinColumn(name = "tb_crop_id") | |||||
| private TBCrop tbCrop; | |||||
| @Column(name = "code") | @Column(name = "code") | ||||
| private String code; | private String code; | ||||
| public void setDeletedBy(TBDetailUser deletedBy) { | public void setDeletedBy(TBDetailUser deletedBy) { | ||||
| this.deletedBy = deletedBy; | this.deletedBy = deletedBy; | ||||
| } | } | ||||
| public TBCrop getTbCrop() { | |||||
| return tbCrop; | |||||
| } | |||||
| public void setTbCrop(TBCrop tbCrop) { | |||||
| this.tbCrop = tbCrop; | |||||
| } | |||||
| } | } |
| inverseJoinColumns = @JoinColumn(name = "tb_detail_users_id"/*, referencedColumnName = "id"*/)) | inverseJoinColumns = @JoinColumn(name = "tb_detail_users_id"/*, referencedColumnName = "id"*/)) | ||||
| private Set<TBDetailUser> tbDetailUsers = new HashSet<>(); | private Set<TBDetailUser> tbDetailUsers = new HashSet<>(); | ||||
| @ManyToMany | |||||
| @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) | |||||
| @JoinTable(name = "tb_crop_code", | |||||
| joinColumns = @JoinColumn(name = "tb_crop_id"/*, referencedColumnName = "id"*/), | |||||
| inverseJoinColumns = @JoinColumn(name = "tb_code_id"/*, referencedColumnName = "id"*/)) | |||||
| private Set<TBCode> tbCodes = new HashSet<>(); | |||||
| @OneToOne(mappedBy = "tbCrop", cascade = CascadeType.ALL) | |||||
| @PrimaryKeyJoinColumn | |||||
| private TBCode tbCode; | |||||
| // @ManyToMany | |||||
| // @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) | |||||
| // @JoinTable(name = "tb_crop_code", | |||||
| // joinColumns = @JoinColumn(name = "tb_crop_id"/*, referencedColumnName = "id"*/), | |||||
| // inverseJoinColumns = @JoinColumn(name = "tb_code_id"/*, referencedColumnName = "id"*/)) | |||||
| // private Set<TBCode> tbCodes = new HashSet<>(); | |||||
| // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove | // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove | ||||
| public Long getId() { | public Long getId() { | ||||
| } | } | ||||
| // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove | // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove | ||||
| public TBCode getTbCode() { | |||||
| return tbCode; | |||||
| } | |||||
| public void setTbCode(TBCode tbCode) { | |||||
| this.tbCode = tbCode; | |||||
| } | |||||
| @Override | @Override | ||||
| public boolean equals(Object o) { | public boolean equals(Object o) { | ||||
| if (this == o) { | if (this == o) { |
| package vn.azteam.tpf.repository.search; | |||||
| import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; | |||||
| import vn.azteam.tpf.domain.TBCodeDetails; | |||||
| public interface TBCodeDetailsSearchRepository extends ElasticsearchRepository<TBCodeDetails, Long> { | |||||
| } |
| package vn.azteam.tpf.repository.search; | |||||
| import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; | |||||
| import vn.azteam.tpf.domain.TBCode; | |||||
| public interface TBCodeSearchRepository extends ElasticsearchRepository<TBCode, Long> { | |||||
| } |
| package vn.azteam.tpf.service; | |||||
| import vn.azteam.tpf.service.dto.TBCodeDetailsDTO; | |||||
| import java.util.List; | |||||
| /** | |||||
| * Service Interface for managing TBCodeDetailsService. | |||||
| */ | |||||
| public interface TBCodeDetailsService { | |||||
| TBCodeDetailsDTO save(TBCodeDetailsDTO tBCodeDetailsDTO); | |||||
| List<TBCodeDetailsDTO> saveAll(List<TBCodeDetailsDTO> tBCodeDetailsDTOs); | |||||
| } |
| package vn.azteam.tpf.service; | package vn.azteam.tpf.service; | ||||
| import org.springframework.data.domain.Page; | |||||
| import org.springframework.data.domain.Pageable; | |||||
| import vn.azteam.tpf.service.dto.CropPersonInChargeDTO; | |||||
| import vn.azteam.tpf.service.dto.TBCropDTO; | |||||
| import vn.azteam.tpf.service.dto.TBCustomerHasCropTypeDTO; | |||||
| import vn.azteam.tpf.service.dto.TBCodeDTO; | |||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Optional; | |||||
| /** | /** | ||||
| * Service Interface for managing TBCode. | * Service Interface for managing TBCode. | ||||
| */ | */ | ||||
| public interface TBCodeService { | public interface TBCodeService { | ||||
| // TBCropDTO save(TBCropDTO tBCropDTO); | |||||
| // | |||||
| // | |||||
| TBCodeDTO save(TBCodeDTO tBCodeDTO); | |||||
| List<TBCodeDTO> saveAll(List<TBCodeDTO> tBCodeDTOs); | |||||
| // /** | // /** | ||||
| // * Update crop's PIC | // * Update crop's PIC | ||||
| // * @param cropPersonInChargeDTO | // * @param cropPersonInChargeDTO |
| return ageDay; | return ageDay; | ||||
| } | } | ||||
| public String generateRandomStringFromUUID(int stringLength) { | |||||
| String qrCode = UUID | |||||
| .randomUUID() | |||||
| .toString() | |||||
| .replace("-", "") | |||||
| .substring(0, stringLength) | |||||
| .toUpperCase(); | |||||
| return qrCode; | |||||
| } | |||||
| // public String generateRandomStringFromUUID(int stringLength) { | |||||
| // String qrCode = UUID | |||||
| // .randomUUID() | |||||
| // .toString() | |||||
| // .replace("-", "") | |||||
| // .substring(0, stringLength) | |||||
| // .toUpperCase(); | |||||
| // return qrCode; | |||||
| // } | |||||
| /** | /** | ||||
| * Get all history of activities | * Get all history of activities |
| package vn.azteam.tpf.service.dto; | |||||
| import java.io.Serializable; | |||||
| public class TBCodeCreationDTO implements Serializable { | |||||
| private Long tBCropId; | |||||
| private String pathImage; | |||||
| private Integer quantity; | |||||
| private String description; | |||||
| public Long gettBCropId() { | |||||
| return tBCropId; | |||||
| } | |||||
| public void settBCropId(Long tBCropId) { | |||||
| this.tBCropId = tBCropId; | |||||
| } | |||||
| public String getPathImage() { | |||||
| return pathImage; | |||||
| } | |||||
| public void setPathImage(String pathImage) { | |||||
| this.pathImage = pathImage; | |||||
| } | |||||
| 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; | |||||
| } | |||||
| } |
| private Long id; | private Long id; | ||||
| private Long tBCropId; | |||||
| private String code; | private String code; | ||||
| private Integer quantity; | private Integer quantity; | ||||
| public void setTbCodeDetails(Set<TBCodeDetails> tbCodeDetails) { | public void setTbCodeDetails(Set<TBCodeDetails> tbCodeDetails) { | ||||
| this.tbCodeDetails = tbCodeDetails; | this.tbCodeDetails = tbCodeDetails; | ||||
| } | } | ||||
| public Long gettBCropId() { | |||||
| return tBCropId; | |||||
| } | |||||
| public void settBCropId(Long tBCropId) { | |||||
| this.tBCropId = tBCropId; | |||||
| } | |||||
| } | } |
| private TBCodeDetailsStatusEnum status; | private TBCodeDetailsStatusEnum status; | ||||
| private Instant expiredDate; | |||||
| // private Instant expiredDate; | |||||
| private Instant createdDate; | private Instant createdDate; | ||||
| this.status = status; | this.status = status; | ||||
| } | } | ||||
| public Instant getExpiredDate() { | |||||
| return expiredDate; | |||||
| } | |||||
| public void setExpiredDate(Instant expiredDate) { | |||||
| this.expiredDate = expiredDate; | |||||
| } | |||||
| public Instant getCreatedDate() { | public Instant getCreatedDate() { | ||||
| return createdDate; | return createdDate; | ||||
| } | } |
| package vn.azteam.tpf.service.impl; | package vn.azteam.tpf.service.impl; | ||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| 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.TBCodeDetails; | |||||
| import vn.azteam.tpf.repository.TBCodeDetailsRepository; | |||||
| import vn.azteam.tpf.repository.search.TBCodeDetailsSearchRepository; | |||||
| import vn.azteam.tpf.service.TBCodeDetailsService; | import vn.azteam.tpf.service.TBCodeDetailsService; | ||||
| import vn.azteam.tpf.service.dto.TBCodeDetailsDTO; | |||||
| import vn.azteam.tpf.service.mapper.TBCodeDetailsMapper; | |||||
| import java.util.ArrayList; | |||||
| import java.util.List; | |||||
| import java.util.stream.Collectors; | |||||
| /** | /** | ||||
| * Service Implementation for managing TBCodeDetails. | * Service Implementation for managing TBCodeDetails. | ||||
| @Service | @Service | ||||
| @Transactional | @Transactional | ||||
| public class TBCodeDetailsImpl implements TBCodeDetailsService { | public class TBCodeDetailsImpl implements TBCodeDetailsService { | ||||
| private final Logger log = LoggerFactory.getLogger(TBCodeDetailsImpl.class); | |||||
| private final TBCodeDetailsRepository tbCodeDetailsRepository; | |||||
| private final TBCodeDetailsMapper tBCodeDetailsMapper; | |||||
| private final TBCodeDetailsSearchRepository tBCodeDetailsSearchRepository; | |||||
| public TBCodeDetailsImpl(TBCodeDetailsRepository tbCodeDetailsRepository, TBCodeDetailsMapper tBCodeDetailsMapper, TBCodeDetailsSearchRepository tBCodeDetailsSearchRepository) { | |||||
| this.tbCodeDetailsRepository = tbCodeDetailsRepository; | |||||
| this.tBCodeDetailsMapper = tBCodeDetailsMapper; | |||||
| this.tBCodeDetailsSearchRepository = tBCodeDetailsSearchRepository; | |||||
| } | |||||
| @Override | |||||
| public TBCodeDetailsDTO save(TBCodeDetailsDTO tBCodeDetailsDTO) { | |||||
| log.debug("Request to save TBCodeDetailsDTO : {}", tBCodeDetailsDTO); | |||||
| TBCodeDetails tBCodeDetails = tBCodeDetailsMapper.toEntity(tBCodeDetailsDTO); | |||||
| tBCodeDetails = tbCodeDetailsRepository.save(tBCodeDetails); | |||||
| TBCodeDetailsDTO result = tBCodeDetailsMapper.toDto(tBCodeDetails); | |||||
| tBCodeDetailsSearchRepository.save(tBCodeDetails); | |||||
| return result; | |||||
| } | |||||
| @Override | |||||
| public List<TBCodeDetailsDTO> saveAll(List<TBCodeDetailsDTO> tBCodeDetailsDTOs) { | |||||
| List<TBCodeDetails> tbCodes = new ArrayList<>(); | |||||
| for (TBCodeDetailsDTO tBCodeDetailsDTO : tBCodeDetailsDTOs) { | |||||
| TBCodeDetails tbCodeDetails = tBCodeDetailsMapper.toEntity(tBCodeDetailsDTO); | |||||
| tbCodes.add(tbCodeDetails); | |||||
| } | |||||
| tbCodes = tbCodeDetailsRepository.saveAll(tbCodes); | |||||
| return tbCodes.stream().map(tBCodeDetailsMapper::toDto).collect(Collectors.toList()); | |||||
| } | |||||
| } | } |
| package vn.azteam.tpf.service.impl; | package vn.azteam.tpf.service.impl; | ||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| 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.repository.TBCodeRepository; | |||||
| import vn.azteam.tpf.repository.search.TBCodeSearchRepository; | |||||
| import vn.azteam.tpf.service.TBCodeService; | import vn.azteam.tpf.service.TBCodeService; | ||||
| import vn.azteam.tpf.service.dto.TBCodeDTO; | |||||
| import vn.azteam.tpf.service.mapper.TBCodeMapper; | |||||
| import java.util.ArrayList; | |||||
| import java.util.List; | |||||
| import java.util.stream.Collectors; | |||||
| /** | /** | ||||
| * Service Implementation for managing TBCode. | * Service Implementation for managing TBCode. | ||||
| @Service | @Service | ||||
| @Transactional | @Transactional | ||||
| public class TBCodeServiceImpl implements TBCodeService { | public class TBCodeServiceImpl implements TBCodeService { | ||||
| private final Logger log = LoggerFactory.getLogger(TBCodeServiceImpl.class); | |||||
| private final TBCodeRepository tbCodeRepository; | |||||
| private final TBCodeMapper tBCodeMapper; | |||||
| private final TBCodeSearchRepository tBCodeSearchRepository; | |||||
| public TBCodeServiceImpl(TBCodeRepository tbCodeRepository, TBCodeMapper tBCodeMapper, TBCodeSearchRepository tBCodeSearchRepository) { | |||||
| this.tbCodeRepository = tbCodeRepository; | |||||
| this.tBCodeMapper = tBCodeMapper; | |||||
| this.tBCodeSearchRepository = tBCodeSearchRepository; | |||||
| } | |||||
| @Override | |||||
| public TBCodeDTO save(TBCodeDTO tBCodeDTO) { | |||||
| log.debug("Request to save TBCodeDTO : {}", tBCodeDTO); | |||||
| TBCode tbCode = tBCodeMapper.toEntity(tBCodeDTO); | |||||
| tbCode = tbCodeRepository.save(tbCode); | |||||
| TBCodeDTO result = tBCodeMapper.toDto(tbCode); | |||||
| tBCodeSearchRepository.save(tbCode); | |||||
| return result; | |||||
| } | |||||
| @Override | |||||
| public List<TBCodeDTO> saveAll(List<TBCodeDTO> tBCodeDTOs) { | |||||
| List<TBCode> tbCodes = new ArrayList<>(); | |||||
| for (TBCodeDTO tbCodeDTO : tBCodeDTOs) { | |||||
| TBCode tbCode = tBCodeMapper.toEntity(tbCodeDTO); | |||||
| tbCodes.add(tbCode); | |||||
| } | |||||
| tbCodes = tbCodeRepository.saveAll(tbCodes); | |||||
| return tbCodes.stream().map(tBCodeMapper::toDto).collect(Collectors.toList()); | |||||
| } | |||||
| } | } |
| package vn.azteam.tpf.web.rest; | |||||
| import com.codahale.metrics.annotation.Timed; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.data.domain.Page; | |||||
| import org.springframework.data.domain.Pageable; | |||||
| import org.springframework.http.HttpHeaders; | |||||
| import org.springframework.http.ResponseEntity; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import vn.azteam.tpf.domain.TBCodeDetailsStatusEnum; | |||||
| import vn.azteam.tpf.domain.TBCodeStatusEnum; | |||||
| import vn.azteam.tpf.service.*; | |||||
| import vn.azteam.tpf.service.dto.*; | |||||
| import vn.azteam.tpf.service.util.PageableUtil; | |||||
| import vn.azteam.tpf.service.util.UserRoleUtil; | |||||
| import vn.azteam.tpf.web.rest.errors.BadRequestAlertException; | |||||
| 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.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; | |||||
| import java.util.stream.Collectors; | |||||
| @RestController | |||||
| @RequestMapping("/api") | |||||
| public class TBCodeResource { | |||||
| private static final String ENTITY_NAME = "tBCode"; | |||||
| private final Logger log = LoggerFactory.getLogger(TBCodeResource.class); | |||||
| private final TBCodeService tBCodeService; | |||||
| private final TBCodeDetailsService tbCodeDetailsService; | |||||
| private final TBCropService tBCropService; | |||||
| private final UserService userService; | |||||
| private final TBCodeQueryService tBCodeQueryService; | |||||
| private final UserRoleUtil userRoleUtil; | |||||
| private final PageableUtil pageableUtil; | |||||
| public TBCodeResource(TBCodeService tBCodeService, TBCodeDetailsService tbCodeDetailsService, TBCropService tBCropService, UserService userService, TBCodeQueryService tBCodeQueryService, UserRoleUtil userRoleUtil, PageableUtil pageableUtil) { | |||||
| this.tBCodeService = tBCodeService; | |||||
| this.tbCodeDetailsService = tbCodeDetailsService; | |||||
| this.tBCropService = tBCropService; | |||||
| this.userService = userService; | |||||
| this.tBCodeQueryService = tBCodeQueryService; | |||||
| this.userRoleUtil = userRoleUtil; | |||||
| this.pageableUtil = pageableUtil; | |||||
| } | |||||
| /** | |||||
| * GET /tb-codes-dropdown-list : get all the tBCode for dropdown options. | |||||
| * | |||||
| * @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") | |||||
| @Timed | |||||
| public ResponseEntity<List<TBCodeDTO>> getAllTBCodesForDropdown(TBCodeCriteria 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())) | |||||
| .sorted(Comparator.comparing( | |||||
| TBCodeDTO::getCreatedDate, | |||||
| Comparator.nullsFirst(Comparator.naturalOrder())).reversed()) | |||||
| .collect(Collectors.toList()); | |||||
| return ResponseEntity.ok().headers(null).body(result); | |||||
| } | |||||
| /** | |||||
| * GET /tb-codes : get all the tBCodes. | |||||
| * | |||||
| * @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 | |||||
| */ | |||||
| @GetMapping("/tb-codes") | |||||
| @Timed | |||||
| public ResponseEntity<List<TBCodeDTO>> getAllTBCodes(TBCodeCriteria criteria, Pageable pageable) { | |||||
| log.debug("REST request to get TBCrops 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())) | |||||
| .sorted(Comparator.comparing( | |||||
| TBCodeDTO::getCreatedDate, | |||||
| Comparator.nullsFirst(Comparator.naturalOrder())).reversed()) | |||||
| .collect(Collectors.toList()); | |||||
| Page<TBCodeDTO> pageResult = pageableUtil.changeTBCodeDTOToPageFromList(result, pageable); | |||||
| for (TBCodeDTO itemResult : result) { | |||||
| //logger.error("Start date: " + itemResult.getStartDate()); | |||||
| } | |||||
| HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(pageResult, "/api/tb-codes"); | |||||
| return ResponseEntity.ok().headers(headers).body(pageResult.getContent()); | |||||
| } | |||||
| @PostMapping("/tb-codes") | |||||
| @Timed | |||||
| public ResponseEntity<TBCodeDTO> createTBCrop(@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(); | |||||
| if (tBCodeCreationDTO.gettBCropId() != null) { | |||||
| throw new BadRequestAlertException("1047", ENTITY_NAME, "1047"); | |||||
| } | |||||
| if (tBCodeCreationDTO.getQuantity() != null && tBCodeCreationDTO.getQuantity() <= 0) { | |||||
| throw new BadRequestAlertException("1047", ENTITY_NAME, "1047"); | |||||
| } | |||||
| Optional<TBCropDTO> tbCropDTO = tBCropService.findOne(tBCodeCreationDTO.gettBCropId()); | |||||
| if (!tbCropDTO.isPresent()) { | |||||
| throw new BadRequestAlertException("1019", ENTITY_NAME, "1019"); | |||||
| } | |||||
| try { | |||||
| TBCodeDTO tBCodeDTO = new TBCodeDTO(); | |||||
| tBCodeDTO.setDescription(StringUtils.isNotBlank(tBCodeCreationDTO.getDescription()) ? | |||||
| tBCodeCreationDTO.getDescription() : ""); | |||||
| tBCodeDTO.setQuantity(tBCodeCreationDTO.getQuantity()); | |||||
| tBCodeDTO.setPathImage(StringUtils.isNotBlank(tBCodeCreationDTO.getPathImage()) ? | |||||
| tBCodeCreationDTO.getPathImage() : ""); | |||||
| tBCodeDTO.setCreatedDate(Instant.now()); | |||||
| tBCodeDTO.setCreatedById(currentUser.getUserId()); | |||||
| tBCodeDTO.setStatus(TBCodeStatusEnum.NEW); | |||||
| TBCodeDTO result = null; | |||||
| Boolean hasViolationException = false; | |||||
| do { | |||||
| try { | |||||
| tBCodeDTO.setCode(RandomStringUtil.generateRandomStringFromUUID(8)); | |||||
| result = tBCodeService.save(tBCodeDTO); | |||||
| } catch (org.springframework.dao.DataIntegrityViolationException ex) { | |||||
| if (ex.getMessage().contains("ux_tb_code_code")) { | |||||
| hasViolationException = true; | |||||
| } else { | |||||
| throw ex; | |||||
| } | |||||
| } | |||||
| } | |||||
| while (hasViolationException); | |||||
| if (result.getId() != null) { | |||||
| List<TBCodeDetailsDTO> tbCodeDetailsDTOS = new ArrayList<>(); | |||||
| for (int i = 1; i <= tBCodeCreationDTO.getQuantity(); i++) { | |||||
| TBCodeDetailsDTO codeDetailsDTO = new TBCodeDetailsDTO(); | |||||
| codeDetailsDTO.setCode(tBCodeDTO.getCode()); | |||||
| codeDetailsDTO.setTbCode(tBCodeDTO); | |||||
| codeDetailsDTO.setNumberScan(0); | |||||
| codeDetailsDTO.setStatus(TBCodeDetailsStatusEnum.NEW); | |||||
| codeDetailsDTO.setCreatedDate(Instant.now()); | |||||
| tBCodeDTO.setCreatedById(currentUser.getUserId()); | |||||
| tbCodeDetailsDTOS.add(codeDetailsDTO); | |||||
| } | |||||
| tbCodeDetailsService.saveAll(tbCodeDetailsDTOS); | |||||
| } | |||||
| return ResponseEntity.created(new URI("/api/tb-codes/" + result.getId())) | |||||
| .headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())) | |||||
| .body(result); | |||||
| } catch (Exception exception) { | |||||
| throw new RuntimeException(); | |||||
| } | |||||
| } | |||||
| } |
| import com.codahale.metrics.annotation.Timed; | import com.codahale.metrics.annotation.Timed; | ||||
| import io.github.jhipster.service.filter.LongFilter; | import io.github.jhipster.service.filter.LongFilter; | ||||
| import io.github.jhipster.service.filter.StringFilter; | import io.github.jhipster.service.filter.StringFilter; | ||||
| import io.swagger.v3.oas.annotations.security.SecurityRequirement; | |||||
| import io.github.jhipster.web.util.ResponseUtil; | |||||
| import org.apache.commons.logging.Log; | import org.apache.commons.logging.Log; | ||||
| import org.apache.commons.logging.LogFactory; | import org.apache.commons.logging.LogFactory; | ||||
| import org.casbin.jcasbin.main.Enforcer; | import org.casbin.jcasbin.main.Enforcer; | ||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.data.domain.Page; | |||||
| import org.springframework.data.domain.Pageable; | |||||
| import org.springframework.http.HttpHeaders; | |||||
| import org.springframework.http.HttpStatus; | import org.springframework.http.HttpStatus; | ||||
| import org.springframework.http.ResponseEntity; | |||||
| import org.springframework.util.StringUtils; | import org.springframework.util.StringUtils; | ||||
| import org.springframework.web.bind.annotation.*; | |||||
| import vn.azteam.tpf.service.*; | import vn.azteam.tpf.service.*; | ||||
| import vn.azteam.tpf.service.dto.*; | import vn.azteam.tpf.service.dto.*; | ||||
| import vn.azteam.tpf.service.util.PageableUtil; | import vn.azteam.tpf.service.util.PageableUtil; | ||||
| import vn.azteam.tpf.web.rest.errors.ForbiddenException; | import vn.azteam.tpf.web.rest.errors.ForbiddenException; | ||||
| import vn.azteam.tpf.web.rest.util.HeaderUtil; | import vn.azteam.tpf.web.rest.util.HeaderUtil; | ||||
| import vn.azteam.tpf.web.rest.util.PaginationUtil; | import vn.azteam.tpf.web.rest.util.PaginationUtil; | ||||
| import io.github.jhipster.web.util.ResponseUtil; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.data.domain.Page; | |||||
| import org.springframework.data.domain.Pageable; | |||||
| import org.springframework.http.HttpHeaders; | |||||
| import org.springframework.http.ResponseEntity; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import vn.azteam.tpf.web.rest.util.RandomStringUtil; | |||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||
| 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.*; | |||||
| import java.util.Comparator; | |||||
| import java.util.List; | |||||
| import java.util.Optional; | |||||
| import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||
| import static vn.azteam.tpf.Constants.Constants.*; | import static vn.azteam.tpf.Constants.Constants.*; | ||||
| import static vn.azteam.tpf.security.contants.Contants.*; | |||||
| import static vn.azteam.tpf.security.contants.Contants.CUSID_API_KEY; | |||||
| /** | /** | ||||
| * REST controller for managing TBCrop. | * REST controller for managing TBCrop. | ||||
| if (tBCropDTO.getId() != null) { | if (tBCropDTO.getId() != null) { | ||||
| throw new BadRequestAlertException("1047", ENTITY_NAME, "1047"); | throw new BadRequestAlertException("1047", ENTITY_NAME, "1047"); | ||||
| } | } | ||||
| if(currentUser.getCustomerId() == null){ | |||||
| if (currentUser.getCustomerId() == null) { | |||||
| throw new BadRequestAlertException("1018", ENTITY_NAME, "1018"); | throw new BadRequestAlertException("1018", ENTITY_NAME, "1018"); | ||||
| } | } | ||||
| if(tBCropDTO.getTbCropTypeId() == null){ | |||||
| if (tBCropDTO.getTbCropTypeId() == null) { | |||||
| throw new BadRequestAlertException("1031", ENTITY_NAME, "1031"); | throw new BadRequestAlertException("1031", ENTITY_NAME, "1031"); | ||||
| } | } | ||||
| if (!userRoleUtil.currentUserHasPermissionByEntityId(tBCropDTO.getNetHouseId())) { | if (!userRoleUtil.currentUserHasPermissionByEntityId(tBCropDTO.getNetHouseId())) { | ||||
| } | } | ||||
| TBEntityDTO tbEntityDTO = tbEntityService.findOne(tBCropDTO.getNetHouseId()).get(); | TBEntityDTO tbEntityDTO = tbEntityService.findOne(tBCropDTO.getNetHouseId()).get(); | ||||
| if (currentUser.getCustomerId() != null | if (currentUser.getCustomerId() != null | ||||
| && !currentUser.getCustomerId().equals(tbEntityDTO.getTbCustomerId())){ | |||||
| && !currentUser.getCustomerId().equals(tbEntityDTO.getTbCustomerId())) { | |||||
| throw new BadRequestAlertException("1019", ENTITY_NAME, "1019"); | throw new BadRequestAlertException("1019", ENTITY_NAME, "1019"); | ||||
| } | } | ||||
| //Set created date to current timestamp | //Set created date to current timestamp | ||||
| Boolean hasViolationException = false; | Boolean hasViolationException = false; | ||||
| do { | do { | ||||
| try { | try { | ||||
| String qrCode = tBCropQueryService.generateRandomStringFromUUID(8); | |||||
| String qrCode = RandomStringUtil.generateRandomStringFromUUID(8); | |||||
| tBCropDTO.setQrCode(qrCode); | tBCropDTO.setQrCode(qrCode); | ||||
| result = tBCropService.save(tBCropDTO); | result = tBCropService.save(tBCropDTO); | ||||
| } catch (org.springframework.dao.DataIntegrityViolationException ex) { | } catch (org.springframework.dao.DataIntegrityViolationException ex) { | ||||
| .headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, tBCropDTO.getId().toString())) | .headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, tBCropDTO.getId().toString())) | ||||
| .body(result); | .body(result); | ||||
| } | } | ||||
| /** | /** | ||||
| * GET /tb-crops-dropdown-list : get all the tBCrops for dropdown options. | * GET /tb-crops-dropdown-list : get all the tBCrops for dropdown options. | ||||
| * | * | ||||
| return ResponseEntity.ok().headers(null).body(result); | return ResponseEntity.ok().headers(null).body(result); | ||||
| } | } | ||||
| /** | /** | ||||
| * GET /tb-crops : get all the tBCrops. | * GET /tb-crops : get all the tBCrops. | ||||
| * | * | ||||
| //Authorize get list crop by customer of current user | //Authorize get list crop by customer of current user | ||||
| List<TBCropDTO> result = page.getContent().stream() | List<TBCropDTO> result = page.getContent().stream() | ||||
| .filter(item -> userRoleUtil.currentUserHasPermissionByCustomerId(item.getId()) | |||||
| && userRoleUtil.currentUserHasPermissionByCropId(item.getId())) | |||||
| .sorted(Comparator.comparing( | |||||
| TBCropDTO::getCreatedDate, | |||||
| Comparator.nullsFirst(Comparator.naturalOrder())).reversed()) | |||||
| .collect(Collectors.toList()); | |||||
| .filter(item -> userRoleUtil.currentUserHasPermissionByCustomerId(item.getId()) | |||||
| && userRoleUtil.currentUserHasPermissionByCropId(item.getId())) | |||||
| .sorted(Comparator.comparing( | |||||
| TBCropDTO::getCreatedDate, | |||||
| Comparator.nullsFirst(Comparator.naturalOrder())).reversed()) | |||||
| .collect(Collectors.toList()); | |||||
| Page<TBCropDTO> pageResult = pageableUtil.changeTBCropDTOToPageFromList(result, pageable); | Page<TBCropDTO> pageResult = pageableUtil.changeTBCropDTOToPageFromList(result, pageable); | ||||
| for(TBCropDTO itemResult : result) { | |||||
| logger.error("Start date: " + itemResult.getStartDate()); | |||||
| for (TBCropDTO itemResult : result) { | |||||
| logger.error("Start date: " + itemResult.getStartDate()); | |||||
| } | } | ||||
| HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(pageResult, "/api/tb-crops"); | HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(pageResult, "/api/tb-crops"); | ||||
| return ResponseEntity.ok().headers(headers).body(pageResult.getContent()); | return ResponseEntity.ok().headers(headers).body(pageResult.getContent()); | ||||
| } | } | ||||
| @GetMapping("/ots/tb-crops-by-customer") | @GetMapping("/ots/tb-crops-by-customer") | ||||
| @Timed | @Timed | ||||
| public ResponseEntity<List<TBCropDTO>> getTBCropsByCustomer(HttpServletRequest request, TBCropCriteria criteria, Pageable pageable) { | public ResponseEntity<List<TBCropDTO>> getTBCropsByCustomer(HttpServletRequest request, TBCropCriteria criteria, Pageable pageable) { | ||||
| .collect(Collectors.toList()); | .collect(Collectors.toList()); | ||||
| Page<TBCropDTO> pageResult = pageableUtil.changeTBCropDTOToPageFromList(result, pageable); | Page<TBCropDTO> pageResult = pageableUtil.changeTBCropDTOToPageFromList(result, pageable); | ||||
| for(TBCropDTO itemResult : result) { | |||||
| logger.error("Start date: " + itemResult.getStartDate()); | |||||
| for (TBCropDTO itemResult : result) { | |||||
| logger.error("Start date: " + itemResult.getStartDate()); | |||||
| } | } | ||||
| HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(pageResult, "/api/ots/tb-crops-by-customer"); | HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(pageResult, "/api/ots/tb-crops-by-customer"); | ||||
| return ResponseEntity.ok().headers(headers).body(pageResult.getContent()); | return ResponseEntity.ok().headers(headers).body(pageResult.getContent()); | ||||
| } | } | ||||
| /** | /** | ||||
| * GET /tb-crops/:cropId : get the "id" tBCrop. | * GET /tb-crops/:cropId : get the "id" tBCrop. | ||||
| * | * | ||||
| Long customer_id = Long.parseLong(request.getHeader(CUSID_API_KEY)); | Long customer_id = Long.parseLong(request.getHeader(CUSID_API_KEY)); | ||||
| Optional<TBCropDTO> tBCropDTO = tBCropService.findOne(cropId); | Optional<TBCropDTO> tBCropDTO = tBCropService.findOne(cropId); | ||||
| if (!tBCropDTO.get().getTbCustomerId().equals(customer_id)){ | |||||
| if (!tBCropDTO.get().getTbCustomerId().equals(customer_id)) { | |||||
| throw new ForbiddenException(); | throw new ForbiddenException(); | ||||
| } | } | ||||
| return ResponseUtil.wrapOrNotFound(tBCropDTO); | return ResponseUtil.wrapOrNotFound(tBCropDTO); | ||||
| } | } | ||||
| /** | /** | ||||
| * GET /tb-crops/count : count all the tBCrops. | * GET /tb-crops/count : count all the tBCrops. | ||||
| * | * | ||||
| */ | */ | ||||
| @GetMapping("/ots/tb-crops-detail/{id}") | @GetMapping("/ots/tb-crops-detail/{id}") | ||||
| @Timed | @Timed | ||||
| public ResponseEntity<TBCropDetailDTO> getDetailTBCropForOts(@RequestParam(required=false) String type, @PathVariable Long id, HttpServletRequest request, Pageable pageable) { | |||||
| public ResponseEntity<TBCropDetailDTO> getDetailTBCropForOts(@RequestParam(required = false) String type, @PathVariable Long id, HttpServletRequest request, Pageable pageable) { | |||||
| log.debug("REST request to get TBCrop detail for app : {}", id); | log.debug("REST request to get TBCrop detail for app : {}", id); | ||||
| return getCropDetailDTOResponseEntityOts(type, id, request, pageable); | return getCropDetailDTOResponseEntityOts(type, id, request, pageable); | ||||
| && activity.getCreatedById() == null); | && activity.getCreatedById() == null); | ||||
| // Lo Uom | // Lo Uom | ||||
| if(tBCropDTO.get().getTbCropTypeId() == 1) { | |||||
| if (tBCropDTO.get().getTbCropTypeId() == 1) { | |||||
| // Get sowing Date | // Get sowing Date | ||||
| TBActivityDTO nurseryActivity = allActivities.stream() | TBActivityDTO nurseryActivity = allActivities.stream() | ||||
| .sorted(Comparator.comparing( | .sorted(Comparator.comparing( | ||||
| if (nurseryActivity != null) { | if (nurseryActivity != null) { | ||||
| tbCropDetailDTO.setSowingDate(nurseryActivity.getExecuteDate()); | tbCropDetailDTO.setSowingDate(nurseryActivity.getExecuteDate()); | ||||
| List<TBObjectUpdateDTO> tbObjectUpdateDTOs = tbObjectUpdateService.findByTBActivityId(nurseryActivity.getId(), Pageable.unpaged()); | List<TBObjectUpdateDTO> tbObjectUpdateDTOs = tbObjectUpdateService.findByTBActivityId(nurseryActivity.getId(), Pageable.unpaged()); | ||||
| if(tbObjectUpdateDTOs!= null && tbObjectUpdateDTOs.size() > 0) { | |||||
| if (tbObjectUpdateDTOs != null && tbObjectUpdateDTOs.size() > 0) { | |||||
| tbObjectUpdateDTOs.forEach(item -> { | tbObjectUpdateDTOs.forEach(item -> { | ||||
| if (item.getTbObjectParameterDTO().getName().equals(THOI_GIAN_NGAM_HAT)) { | if (item.getTbObjectParameterDTO().getName().equals(THOI_GIAN_NGAM_HAT)) { | ||||
| item.setIndex(item.getIndex() != null && !item.getIndex().isEmpty() ? item.getIndex() : "0"); | item.setIndex(item.getIndex() != null && !item.getIndex().isEmpty() ? item.getIndex() : "0"); | ||||
| } | } | ||||
| } | } | ||||
| //Lo Trong | //Lo Trong | ||||
| if(tBCropDTO.get().getTbCropTypeId() == 2) { | |||||
| if (tBCropDTO.get().getTbCropTypeId() == 2) { | |||||
| // Get planting Date | // Get planting Date | ||||
| TBActivityDTO plantingActivity = allActivities.stream() | TBActivityDTO plantingActivity = allActivities.stream() | ||||
| .sorted(Comparator.comparing( | .sorted(Comparator.comparing( | ||||
| List<Long> listActivities = allActivities.stream().map(TBActivityDTO::getId).collect(Collectors.toList()); | List<Long> listActivities = allActivities.stream().map(TBActivityDTO::getId).collect(Collectors.toList()); | ||||
| List<TBObjectUpdateDTO> tbObjectUpdateDTOs = tbObjectUpdateService.findByInListTBActivityId(listActivities, Pageable.unpaged()); | List<TBObjectUpdateDTO> tbObjectUpdateDTOs = tbObjectUpdateService.findByInListTBActivityId(listActivities, Pageable.unpaged()); | ||||
| if(tbObjectUpdateDTOs!= null && tbObjectUpdateDTOs.size() > 0) { | |||||
| if (tbObjectUpdateDTOs != null && tbObjectUpdateDTOs.size() > 0) { | |||||
| tbObjectUpdateDTOs.forEach(item -> { | tbObjectUpdateDTOs.forEach(item -> { | ||||
| if (item.getTbObjectParameterDTO().getName().equals(SO_LUONG_CAY_TRONG)) { | if (item.getTbObjectParameterDTO().getName().equals(SO_LUONG_CAY_TRONG)) { | ||||
| item.setIndex(item.getIndex() != null && !item.getIndex().isEmpty() ? item.getIndex() : "0"); | 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]",""))); | |||||
| 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)) { | if (item.getTbObjectParameterDTO().getName().equals(SO_LUONG_LOAI_BO)) { | ||||
| item.setIndex(item.getIndex() != null && !item.getIndex().isEmpty() ? item.getIndex() : "0"); | item.setIndex(item.getIndex() != null && !item.getIndex().isEmpty() ? item.getIndex() : "0"); | ||||
| Integer currentNumberPlants = tbCropDetailDTO.getNumberPlants() - Integer.parseInt(item.getIndex().replaceAll("[^0-9]","")); | |||||
| Integer currentNumberPlants = tbCropDetailDTO.getNumberPlants() - Integer.parseInt(item.getIndex().replaceAll("[^0-9]", "")); | |||||
| tbCropDetailDTO.setNumberCurrentPlants(currentNumberPlants > 0 ? currentNumberPlants : 0); | tbCropDetailDTO.setNumberCurrentPlants(currentNumberPlants > 0 ? currentNumberPlants : 0); | ||||
| } | } | ||||
| }); | }); | ||||
| //Filter assignment croptype by customer | //Filter assignment croptype by customer | ||||
| if (currentUser.get().getCustomerId() != null) { | if (currentUser.get().getCustomerId() != null) { | ||||
| List<Long> ListActivityTypeId = tBCropService.getListActivityTypeIdByByCustomerAndCropType(currentUser.get().getCustomerId(),tBCropDTO.get().getTbCropTypeId()); | |||||
| List<Long> ListActivityTypeId = tBCropService.getListActivityTypeIdByByCustomerAndCropType(currentUser.get().getCustomerId(), tBCropDTO.get().getTbCropTypeId()); | |||||
| allActivities = allActivities.stream().filter(item -> ListActivityTypeId.contains(item.getActivityTypeId())).collect(Collectors.toList()); | allActivities = allActivities.stream().filter(item -> ListActivityTypeId.contains(item.getActivityTypeId())).collect(Collectors.toList()); | ||||
| } | } | ||||
| if (isRequestedFromWeb) { | if (isRequestedFromWeb) { | ||||
| tBCropQueryService.getActivityTimeline(id, allActivities, pageable); | tBCropQueryService.getActivityTimeline(id, allActivities, pageable); | ||||
| tbCropDetailDTO.setActivityTimeline(activityTimeline); | tbCropDetailDTO.setActivityTimeline(activityTimeline); | ||||
| } else { | } else { | ||||
| allActivities = pageableUtil.changeTBActivityDTOToPageFromList(allActivities,pageable).getContent(); | |||||
| allActivities = pageableUtil.changeTBActivityDTOToPageFromList(allActivities, pageable).getContent(); | |||||
| tbCropDetailDTO.setActivities(allActivities); | tbCropDetailDTO.setActivities(allActivities); | ||||
| } | } | ||||
| Pageable pageable) { | Pageable pageable) { | ||||
| Long customerId = Long.parseLong(request.getHeader(CUSID_API_KEY)); | Long customerId = Long.parseLong(request.getHeader(CUSID_API_KEY)); | ||||
| Optional<TBCropDTO> tBCropDTO = tBCropService.findOne(id); | Optional<TBCropDTO> tBCropDTO = tBCropService.findOne(id); | ||||
| if (!tBCropDTO.isPresent()){ | |||||
| if (!tBCropDTO.isPresent()) { | |||||
| throw new BadRequestAlertException("Customer not found", ENTITY_NAME, "idinvalid"); | throw new BadRequestAlertException("Customer not found", ENTITY_NAME, "idinvalid"); | ||||
| } | } | ||||
| if (!tBCropDTO.get().getTbCustomerId().equals(customerId)){ | |||||
| if (!tBCropDTO.get().getTbCustomerId().equals(customerId)) { | |||||
| throw new ForbiddenException(); | throw new ForbiddenException(); | ||||
| } | } | ||||
| Optional<UserDTO> currentUser = userService.getCurrentUserDTO(); | Optional<UserDTO> currentUser = userService.getCurrentUserDTO(); | ||||
| && activity.getCreatedById() == null); | && activity.getCreatedById() == null); | ||||
| //Filter assignment croptype by customer | //Filter assignment croptype by customer | ||||
| if (currentUser.get().getCustomerId() != null) { | if (currentUser.get().getCustomerId() != null) { | ||||
| List<Long> ListActivityTypeId = tBCropService.getListActivityTypeIdByByCustomerAndCropType(currentUser.get().getCustomerId(),tBCropDTO.get().getTbCropTypeId()); | |||||
| List<Long> ListActivityTypeId = tBCropService.getListActivityTypeIdByByCustomerAndCropType(currentUser.get().getCustomerId(), tBCropDTO.get().getTbCropTypeId()); | |||||
| allActivities = allActivities.stream().filter(item -> ListActivityTypeId.contains(item.getActivityTypeId())).collect(Collectors.toList()); | allActivities = allActivities.stream().filter(item -> ListActivityTypeId.contains(item.getActivityTypeId())).collect(Collectors.toList()); | ||||
| } | } | ||||
| allActivities = pageableUtil.changeTBActivityDTOToPageFromList(allActivities,pageable).getContent(); | |||||
| allActivities = pageableUtil.changeTBActivityDTOToPageFromList(allActivities, pageable).getContent(); | |||||
| tbCropDetailDTO.setActivities(allActivities); | tbCropDetailDTO.setActivities(allActivities); | ||||
| TBActivityDTO endActivity = allActivities.stream() | TBActivityDTO endActivity = allActivities.stream() | ||||
| tbCropDetailDTO.setEndOfFarmingDate(endActivity.getExecuteDate()); | tbCropDetailDTO.setEndOfFarmingDate(endActivity.getExecuteDate()); | ||||
| } | } | ||||
| // Lo Uom | // Lo Uom | ||||
| if(tBCropDTO.get().getTbCropTypeId() == 1) { | |||||
| if (tBCropDTO.get().getTbCropTypeId() == 1) { | |||||
| // Get sowing Date | // Get sowing Date | ||||
| TBActivityDTO nurseryActivity = allActivities.stream() | TBActivityDTO nurseryActivity = allActivities.stream() | ||||
| .sorted(Comparator.comparing( | .sorted(Comparator.comparing( | ||||
| if (nurseryActivity != null) { | if (nurseryActivity != null) { | ||||
| tbCropDetailDTO.setSowingDate(nurseryActivity.getExecuteDate()); | tbCropDetailDTO.setSowingDate(nurseryActivity.getExecuteDate()); | ||||
| List<TBObjectUpdateDTO> tbObjectUpdateDTOs = tbObjectUpdateService.findByTBActivityId(nurseryActivity.getId(), Pageable.unpaged()); | List<TBObjectUpdateDTO> tbObjectUpdateDTOs = tbObjectUpdateService.findByTBActivityId(nurseryActivity.getId(), Pageable.unpaged()); | ||||
| if(tbObjectUpdateDTOs!= null && tbObjectUpdateDTOs.size() > 0) { | |||||
| if (tbObjectUpdateDTOs != null && tbObjectUpdateDTOs.size() > 0) { | |||||
| tbObjectUpdateDTOs.forEach(item -> { | tbObjectUpdateDTOs.forEach(item -> { | ||||
| if (item.getTbObjectParameterDTO().getName().equals(THOI_GIAN_NGAM_HAT)) { | if (item.getTbObjectParameterDTO().getName().equals(THOI_GIAN_NGAM_HAT)) { | ||||
| item.setIndex(item.getIndex() != null && !item.getIndex().isEmpty() ? item.getIndex() : "0"); | item.setIndex(item.getIndex() != null && !item.getIndex().isEmpty() ? item.getIndex() : "0"); | ||||
| } | } | ||||
| } | } | ||||
| //Lo Trong | //Lo Trong | ||||
| if(tBCropDTO.get().getTbCropTypeId() == 2) { | |||||
| if (tBCropDTO.get().getTbCropTypeId() == 2) { | |||||
| // Get planting Date | // Get planting Date | ||||
| TBActivityDTO plantingActivity = allActivities.stream() | TBActivityDTO plantingActivity = allActivities.stream() | ||||
| .sorted(Comparator.comparing( | .sorted(Comparator.comparing( | ||||
| List<Long> listActivities = allActivities.stream().map(TBActivityDTO::getId).collect(Collectors.toList()); | List<Long> listActivities = allActivities.stream().map(TBActivityDTO::getId).collect(Collectors.toList()); | ||||
| List<TBObjectUpdateDTO> tbObjectUpdateDTOs = tbObjectUpdateService.findByInListTBActivityId(listActivities, Pageable.unpaged()); | List<TBObjectUpdateDTO> tbObjectUpdateDTOs = tbObjectUpdateService.findByInListTBActivityId(listActivities, Pageable.unpaged()); | ||||
| if(tbObjectUpdateDTOs!= null && tbObjectUpdateDTOs.size() > 0) { | |||||
| if (tbObjectUpdateDTOs != null && tbObjectUpdateDTOs.size() > 0) { | |||||
| tbObjectUpdateDTOs.forEach(item -> { | tbObjectUpdateDTOs.forEach(item -> { | ||||
| if (item.getTbObjectParameterDTO().getName().equals(SO_LUONG_CAY_TRONG)) { | if (item.getTbObjectParameterDTO().getName().equals(SO_LUONG_CAY_TRONG)) { | ||||
| item.setIndex(item.getIndex() != null && !item.getIndex().isEmpty() ? item.getIndex() : "0"); | 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]",""))); | |||||
| 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)) { | if (item.getTbObjectParameterDTO().getName().equals(SO_LUONG_LOAI_BO)) { | ||||
| item.setIndex(item.getIndex() != null && !item.getIndex().isEmpty() ? item.getIndex() : "0"); | item.setIndex(item.getIndex() != null && !item.getIndex().isEmpty() ? item.getIndex() : "0"); | ||||
| Integer currentNumberPlants = tbCropDetailDTO.getNumberPlants() - Integer.parseInt(item.getIndex().replaceAll("[^0-9]","")); | |||||
| Integer currentNumberPlants = tbCropDetailDTO.getNumberPlants() - Integer.parseInt(item.getIndex().replaceAll("[^0-9]", "")); | |||||
| tbCropDetailDTO.setNumberCurrentPlants(currentNumberPlants > 0 ? currentNumberPlants : 0); | tbCropDetailDTO.setNumberCurrentPlants(currentNumberPlants > 0 ? currentNumberPlants : 0); | ||||
| } | } | ||||
| }); | }); |
| package vn.azteam.tpf.web.rest.util; | |||||
| import java.util.UUID; | |||||
| public final class RandomStringUtil { | |||||
| public static String generateRandomStringFromUUID(int stringLength) { | |||||
| String qrCode = UUID | |||||
| .randomUUID() | |||||
| .toString() | |||||
| .replace("-", "") | |||||
| .substring(0, stringLength) | |||||
| .toUpperCase(); | |||||
| return qrCode; | |||||
| } | |||||
| } |
| <!-- jhipster-needle-liquibase-add-column - JHipster will add columns here, do not remove--> | <!-- jhipster-needle-liquibase-add-column - JHipster will add columns here, do not remove--> | ||||
| </createTable> | </createTable> | ||||
| <createTable tableName="tb_assignment"> | |||||
| <column name="tb_detail_users_id" type="bigint"> | |||||
| <constraints nullable="false"/> | |||||
| </column> | |||||
| <column name="tb_crops_id" type="bigint"> | |||||
| <constraints nullable="false"/> | |||||
| </column> | |||||
| </createTable> | |||||
| <addPrimaryKey columnNames="tb_crops_id, tb_detail_users_id" tableName="tb_assignment"/> | |||||
| </changeSet> | </changeSet> | ||||
| <!-- jhipster-needle-liquibase-add-changeset - JHipster will add changesets here, do not remove--> | <!-- jhipster-needle-liquibase-add-changeset - JHipster will add changesets here, do not remove--> |
| <?xml version="1.0" encoding="utf-8"?> | |||||
| <databaseChangeLog | |||||
| xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | |||||
| xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" | |||||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||||
| xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd | |||||
| http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"> | |||||
| <property name="now" value="now()" dbms="h2"/> | |||||
| <property name="now" value="now()" dbms="mysql"/> | |||||
| <property name="autoIncrement" value="true"/> | |||||
| <property name="floatType" value="float4" dbms="postgresql, h2"/> | |||||
| <property name="floatType" value="float" dbms="mysql, oracle, mssql"/> | |||||
| <!-- | |||||
| Added the entity TBCode. | |||||
| --> | |||||
| <changeSet id="20231209075003-1" author="jhipster"> | |||||
| <createTable tableName="tb_code"> | |||||
| <column name="id" type="bigint" autoIncrement="${autoIncrement}"> | |||||
| <constraints primaryKey="true" nullable="false"/> | |||||
| </column> | |||||
| <column name="tb_crop_id" type="bigint"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="code" type="varchar(255)"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="quantity" type="integer"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="description" type="varchar(255)"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="path_image" type="varchar(255)"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="status" type="varchar(255)"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="expired_date" type="timestamp"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="created_date" type="timestamp"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="modified_date" type="timestamp"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="deleted_date" type="timestamp"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="created_by" type="bigint"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="modified_by" type="bigint"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="deleted_by" type="bigint"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <!-- jhipster-needle-liquibase-add-column - JHipster will add columns here, do not remove--> | |||||
| </createTable> | |||||
| </changeSet> | |||||
| <!-- jhipster-needle-liquibase-add-changeset - JHipster will add changesets here, do not remove--> | |||||
| </databaseChangeLog> |
| <?xml version="1.0" encoding="utf-8"?> | |||||
| <databaseChangeLog | |||||
| xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | |||||
| xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" | |||||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||||
| xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd | |||||
| http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"> | |||||
| <property name="now" value="now()" dbms="h2"/> | |||||
| <property name="now" value="now()" dbms="mysql"/> | |||||
| <property name="autoIncrement" value="true"/> | |||||
| <property name="floatType" value="float4" dbms="postgresql, h2"/> | |||||
| <property name="floatType" value="float" dbms="mysql, oracle, mssql"/> | |||||
| <!-- | |||||
| Added the entity TBCode. | |||||
| --> | |||||
| <changeSet id="20231209075004-1" author="jhipster"> | |||||
| <createTable tableName="tb_code_details"> | |||||
| <column name="id" type="bigint" autoIncrement="${autoIncrement}"> | |||||
| <constraints primaryKey="true" nullable="false"/> | |||||
| </column> | |||||
| <column name="tb_code_id" type="bigint"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="code" type="varchar(255)"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="number_scan" type="integer"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="status" type="varchar(255)"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="created_date" type="timestamp"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="modified_date" type="timestamp"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="deleted_date" type="timestamp"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="created_by" type="bigint"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="modified_by" type="bigint"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <column name="deleted_by" type="bigint"> | |||||
| <constraints nullable="true" /> | |||||
| </column> | |||||
| <!-- jhipster-needle-liquibase-add-column - JHipster will add columns here, do not remove--> | |||||
| </createTable> | |||||
| </changeSet> | |||||
| <!-- jhipster-needle-liquibase-add-changeset - JHipster will add changesets here, do not remove--> | |||||
| </databaseChangeLog> |
| <include file="config/liquibase/changelog/20210518074106_added_entity_constraints_TBBlockDetailsReport" relativeToChangelogFile="false"/> | <include file="config/liquibase/changelog/20210518074106_added_entity_constraints_TBBlockDetailsReport" relativeToChangelogFile="false"/> | ||||
| <include file="config/liquibase/changelog/20210518074444_added_entity_TBProductBlockDetailsReport.xml" relativeToChangelogFile="false"/> | <include file="config/liquibase/changelog/20210518074444_added_entity_TBProductBlockDetailsReport.xml" relativeToChangelogFile="false"/> | ||||
| <include file="config/liquibase/changelog/20210329175026_updated_entity_constraints_TBSuppliesUsingDetails.xml" relativeToChangelogFile="false"/> | <include file="config/liquibase/changelog/20210329175026_updated_entity_constraints_TBSuppliesUsingDetails.xml" relativeToChangelogFile="false"/> | ||||
| <include file="config/liquibase/changelog/20231209075003_added_entity_TBCode.xml" relativeToChangelogFile="false"/> | |||||
| <include file="config/liquibase/changelog/20231209075004_added_entity_TBCodeDetails.xml" relativeToChangelogFile="false"/> | |||||
| </databaseChangeLog> | </databaseChangeLog> |