保誠-保戶業務員媒合平台
wayne
2022-03-04 472fd20c108714b28be49d4fedee5bbabe1b2358
pamapi/src/main/java/com/pollex/pam/web/rest/ConsultantResource.java
@@ -1,20 +1,25 @@
package com.pollex.pam.web.rest;
import com.pollex.pam.service.ConsultantService;
import com.pollex.pam.service.dto.*;
import com.pollex.pam.business.aop.logging.audit.AuditLoggingInject;
import com.pollex.pam.business.domain.Appointment;
import com.pollex.pam.business.domain.Consultant;
import com.pollex.pam.business.security.SecurityUtils;
import com.pollex.pam.business.service.AppointmentService;
import com.pollex.pam.business.service.ConsultantService;
import com.pollex.pam.business.service.dto.*;
import org.apache.commons.compress.utils.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import static com.pollex.pam.business.aop.logging.audit.AuditLoggingType.CONSULTANT_SEND_FILL_SATISFACTION_NOTICE;
import static com.pollex.pam.business.aop.logging.audit.AuditLoggingType.EDIT_CONSULTANT_DATA;
@RestController
@RequestMapping("/api/consultant")
@@ -22,6 +27,9 @@
    @Autowired
    ConsultantService consultantService;
    @Autowired
    AppointmentService appointmentService;
    @GetMapping("/favorite")
    public ResponseEntity<List<CustomerFavoriteConsultantDTO>> getMyConsultantList() {
@@ -77,15 +85,23 @@
       return consultantService.getMyAppointment();
    }
    @GetMapping(value = "/avatar/{fileName}", produces = MediaType.IMAGE_JPEG_VALUE)
    public ResponseEntity<byte[]> getAvatarImage(@PathVariable String fileName) throws IOException {
        try {
            Resource resource = new ClassPathResource("static/consultant/" + fileName);
            InputStream in = resource.getInputStream();
            return new ResponseEntity<>(IOUtils.toByteArray(in), HttpStatus.OK);
        } catch (FileNotFoundException e) {
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }
    @GetMapping(value = "/avatar/{agentNo}", produces = MediaType.IMAGE_JPEG_VALUE)
    public ResponseEntity<byte[]> getAvatarImage(@PathVariable String agentNo) throws IOException {
//        try {
//            Resource resource = new ClassPathResource("static/consultant/" + fileName);
//            InputStream in = resource.getInputStream();
//            return new ResponseEntity<>(IOUtils.toByteArray(in), HttpStatus.OK);
//        } catch (FileNotFoundException e) {
//            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
//        }
       InputStream in = consultantService.getAvatarImage(agentNo);
       if(in!=null) {
          return new ResponseEntity<>(IOUtils.toByteArray(in), HttpStatus.OK);
       }else {
          return new ResponseEntity<>(HttpStatus.NOT_FOUND);
       }
    }
    @PostMapping("/record/allAppointmentsView")
@@ -93,4 +109,25 @@
        consultantService.recordAllAppointmentsView();
        return ResponseEntity.noContent().build();
    }
    @AuditLoggingInject(type = EDIT_CONSULTANT_DATA)
    @PostMapping("/edit")
    public ResponseEntity<Consultant> editConsultant(@RequestBody ConsultantEditDTO editDTO) {
       if(!editDTO.getAgentNo().equals(SecurityUtils.getAgentNo())) {
          throw new IllegalAccessError();
       }
       Consultant editResult = consultantService.editConsultant(editDTO);
        return new ResponseEntity<>(editResult, HttpStatus.OK);
    }
    @AuditLoggingInject(type = CONSULTANT_SEND_FILL_SATISFACTION_NOTICE)
    @PostMapping("/sendSatisfactionToClient/{appointmentId}")
    public ResponseEntity<Void> sendSatisfactionToClient(@PathVariable Long appointmentId) {
       Appointment appointment = appointmentService.findById(appointmentId);
       if(!appointment.getAgentNo().equals(SecurityUtils.getAgentNo())) {
          throw new IllegalAccessError();
       }
       consultantService.sendSatisfactionToClient(appointment);
       return ResponseEntity.noContent().build();
    }
}