You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TBCodeDetailsResource.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package vn.azteam.tpf.web.rest;
  2. import com.codahale.metrics.annotation.Timed;
  3. import io.github.jhipster.web.util.ResponseUtil;
  4. import io.searchbox.strings.StringUtils;
  5. import org.slf4j.Logger;
  6. import org.slf4j.LoggerFactory;
  7. import org.springframework.http.ResponseEntity;
  8. import org.springframework.web.bind.annotation.*;
  9. import vn.azteam.tpf.domain.TBCodeStatusEnum;
  10. import vn.azteam.tpf.service.TBCodeDetailsQueryService;
  11. import vn.azteam.tpf.service.TBCodeDetailsService;
  12. import vn.azteam.tpf.service.UserService;
  13. import vn.azteam.tpf.service.dto.TBCodeDetailsDTO;
  14. import vn.azteam.tpf.service.dto.TBCropDetailDTOV2;
  15. import vn.azteam.tpf.service.dto.UserDTO;
  16. import vn.azteam.tpf.service.util.PageableUtil;
  17. import vn.azteam.tpf.service.util.UserRoleUtil;
  18. import vn.azteam.tpf.web.rest.errors.BadRequestAlertException;
  19. import java.time.Instant;
  20. import java.util.Optional;
  21. @RestController
  22. @RequestMapping("/api")
  23. public class TBCodeDetailsResource {
  24. private static final String ENTITY_NAME = "tBCodeDetails";
  25. private final Logger log = LoggerFactory.getLogger(TBCodeDetailsResource.class);
  26. private final TBCodeDetailsService tBCodeDetailsService;
  27. private final UserService userService;
  28. public TBCodeDetailsResource(TBCodeDetailsService tBCodeDetailsService, UserService userService) {
  29. this.tBCodeDetailsService = tBCodeDetailsService;
  30. this.userService = userService;
  31. }
  32. @GetMapping("/tb-code-details/scan/{code}")
  33. public ResponseEntity<TBCropDetailDTOV2> getTBCodeDetailsScan(@PathVariable String code) {
  34. if (StringUtils.isBlank(code)) {
  35. return (ResponseEntity<TBCropDetailDTOV2>) ResponseEntity.badRequest();
  36. }
  37. TBCropDetailDTOV2 tbCropDetailDTOV2ResponseEntity = tBCodeDetailsService.updateNumberScan(code);
  38. return ResponseEntity.ok().headers(null).body(tbCropDetailDTOV2ResponseEntity);
  39. }
  40. @PutMapping("/tb-code-details/update/{id}/status/{status}")
  41. @Timed
  42. public ResponseEntity<TBCodeDetailsDTO> updateTBCodeDetailsStatus(@PathVariable Long id, @PathVariable String
  43. status) {
  44. log.debug("REST request to update tb codes : {}, status {} ", id, status);
  45. if (id == null || org.apache.commons.lang3.StringUtils.isBlank(status)) {
  46. throw new BadRequestAlertException("1039", ENTITY_NAME, "1039");
  47. }
  48. try {
  49. TBCodeStatusEnum.valueOf(status);
  50. } catch (Exception exception) {
  51. throw new BadRequestAlertException("1039", ENTITY_NAME, "1039");
  52. }
  53. UserDTO currentUser = userService.getCurrentUserDTO().get();
  54. TBCodeDetailsDTO tbCodeDetailsDTO = new TBCodeDetailsDTO();
  55. tbCodeDetailsDTO.setId(id);
  56. tbCodeDetailsDTO.setModifiedDate(Instant.now());
  57. tbCodeDetailsDTO.setModifiedById(currentUser.getId());
  58. tbCodeDetailsDTO.setStatus(TBCodeStatusEnum.valueOf(status));
  59. Optional<TBCodeDetailsDTO> tBCodeUpdated =
  60. tBCodeDetailsService.updateStatusTBCodeDetails(tbCodeDetailsDTO);
  61. // if (null != tBCropDTO) {
  62. // sendNotificationPersonInCharge(cropPersonInChargeDTO, listAssignmentPrev);
  63. // }
  64. return ResponseUtil.wrapOrNotFound(tBCodeUpdated);
  65. }
  66. }