保誠-保戶業務員媒合平台
wayne
2021-12-20 2f6a687c97ca0f5d914efe4299586d23a74a1ac9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package com.pollex.pam.web.rest;
 
import com.pollex.pam.domain.Consultant;
import com.pollex.pam.security.SecurityUtils;
import com.pollex.pam.service.ConsultantService;
import com.pollex.pam.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.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
 
@RestController
@RequestMapping("/api/consultant")
public class ConsultantResource {
 
    @Autowired
    ConsultantService consultantService;
 
    @GetMapping("/favorite")
    public ResponseEntity<List<CustomerFavoriteConsultantDTO>> getMyConsultantList() {
        List<CustomerFavoriteConsultantDTO> myConsultants = consultantService.getMyConsultantList();
        return new ResponseEntity<>(myConsultants, HttpStatus.OK);
    }
 
    @PostMapping("/favorite/view")
    public ResponseEntity<Void> recordMyConsultantListView() {
        consultantService.recordMyConsultantListView();
        return ResponseEntity.noContent().build();
    }
 
    @GetMapping("/recommend")
    public ResponseEntity<List<ConsultantDTO>> getRecommendConsultantList() {
        List<ConsultantDTO> recommendConsultantList = consultantService.getRecommendConsultantList();
        return new ResponseEntity<>(recommendConsultantList, HttpStatus.OK);
    }
 
    @PostMapping("/favorite")
    public ResponseEntity<Void> addConsultantToCustomList(@RequestBody AddConsultantParam param) {
        consultantService.addConsultantToCustomList(param);
        return new ResponseEntity<>(HttpStatus.ACCEPTED);
    }
 
    @DeleteMapping("/favorite/{agentNo}")
    public ResponseEntity<Void> removeConsultantFromCustomList(@PathVariable String agentNo) {
        consultantService.removeConsultantFromCustomList(agentNo);
        return new ResponseEntity<>(HttpStatus.OK);
    }
 
 
    @PostMapping("/strictQuery")
    public ResponseEntity<List<ConsultantDTO>> strictQueryConsultant(@RequestBody StrictQueryConsultantParam param) {
        List<ConsultantDTO> queryResult = consultantService.strictQueryConsultant(param);
        return new ResponseEntity<>(queryResult, HttpStatus.OK);
    }
 
    @PostMapping("/fastQuery")
    public ResponseEntity<List<ConsultantDTO>> fastQueryConsultant(@RequestBody FastQueryConsultantParam param) {
        List<ConsultantDTO> queryResult = consultantService.fastQueryConsultant(param);
        return new ResponseEntity<>(queryResult, HttpStatus.OK);
    }
 
    @GetMapping("/detail")
    public ResponseEntity<ConsultantDetailDTO> getConsultantDetail(@RequestParam("agentNo") String agentNo) {
        ConsultantDetailDTO result = consultantService.getConsultantDetail(agentNo);
        return new ResponseEntity<>(result, HttpStatus.OK);
    }
 
    @GetMapping("/getMyAppointment")
    public List<AppointmentCustomerViewDTO> getMyAppointment() {
        return consultantService.getMyAppointment();
    }
 
    @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")
    public ResponseEntity<Void> recordAllAppointmentsView() {
        consultantService.recordAllAppointmentsView();
        return ResponseEntity.noContent().build();
    }
    
    @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);
    }
}