pamapi/src/doc/sql/20220126_w.sql
¤ñ¹ï·sÀÉ®× @@ -0,0 +1,6 @@ ALTER TABLE public.satisfaction ALTER COLUMN customer_id DROP NOT NULL; ALTER TABLE public.satisfaction ADD "type" varchar NULL; -- Auto-generated SQL script #202201261717 UPDATE public.satisfaction SET "type"='APPOINTMENT'; pamapi/src/doc/º¡·N«×/«È¤á¶ñ¼g¥¥xº¡·N«×.txt
¤ñ¹ï·sÀÉ®× @@ -0,0 +1,22 @@ http post : http://localhost:8080/api/satisfaction/system/score 填寫ä¸ç: request body: { "appointmentId": 67, "score":4 } response body: { "id": 93, "customerId": 165, "agentNo": null, "status": "FILLED", "score": 4.0, "appointmentId": 482, "type": "SYSTEM" } pamapi/src/doc/º¡·N«×/«È¤á¶ñ¼gÅU°Ýº¡·N«×.txt
pamapi/src/main/java/com/pollex/pam/appointment/process/ClosedProcess.java
@@ -18,29 +18,29 @@ @Service @Transactional public class ClosedProcess implements AppointmentProcessInterface{ @Autowired AppointmentClosedInfoRepository appointmentClosedInfoRepository; @Autowired AppointmentService appointmentService; @Autowired AppointmentClosedInfoService appointmentClosedInfoService; @Autowired SatisfactionService satisfactionService; @Override public AppointmentClosedInfo create(AbstractAppointmentProcessDTO processDTO) { ClosedProcessDTO closeProcess = toClosedProcessDTO(processDTO); AppointmentClosedInfo closedInfo = new AppointmentClosedInfo(); BeanUtils.copyProperties(closeProcess, closedInfo); Appointment appointment = appointmentService.findById(processDTO.getAppointmentId()); satisfactionService.createSatisfaction(appointment); satisfactionService.createAppointmentSatisfaction(appointment); return appointmentClosedInfoRepository.save(closedInfo); } private ClosedProcessDTO toClosedProcessDTO(AbstractAppointmentProcessDTO processDTO) { ClosedProcessDTO closeProcess = (ClosedProcessDTO)processDTO; BeanUtils.copyProperties(processDTO, closeProcess); @@ -51,7 +51,7 @@ public ContactStatusEnum getProcessType() { return ContactStatusEnum.CLOSED; } @Override public AppointmentClosedInfo editClosedInfo( AbstractAppointmentProcessDTO abstractDTO @@ -60,6 +60,6 @@ BeanUtils.copyProperties(closeProcess, closedInfo); return appointmentClosedInfoRepository.save(closedInfo); } } pamapi/src/main/java/com/pollex/pam/appointment/process/DoneProcess.java
@@ -18,26 +18,26 @@ @Service @Transactional public class DoneProcess implements AppointmentProcessInterface{ @Autowired AppointmentClosedInfoRepository appointmentClosedInfoRepository; @Autowired AppointmentClosedInfoService appointmentClosedInfoService; @Autowired SatisfactionService satisfactionService; @Autowired AppointmentService appointmentService; @Override public AppointmentClosedInfo create(AbstractAppointmentProcessDTO processDTO) { DoneProcessDTO doneProcess = toDoneProcessDTO(processDTO); AppointmentClosedInfo closedInfo = new AppointmentClosedInfo(); BeanUtils.copyProperties(doneProcess, closedInfo); Appointment appointment = appointmentService.findById(processDTO.getAppointmentId()); satisfactionService.createSatisfaction(appointment); satisfactionService.createAppointmentSatisfaction(appointment); return appointmentClosedInfoRepository.save(closedInfo); } @@ -45,7 +45,7 @@ public ContactStatusEnum getProcessType() { return ContactStatusEnum.DONE; } @Override public AppointmentClosedInfo editClosedInfo( AbstractAppointmentProcessDTO abstractDTO @@ -60,5 +60,5 @@ BeanUtils.copyProperties(abstractDTO, doneProcess); return doneProcess; } } pamapi/src/main/java/com/pollex/pam/domain/Satisfaction.java
@@ -12,6 +12,8 @@ import javax.persistence.Id; import javax.persistence.Table; import com.pollex.pam.enums.PersonalNotificationRoleEnum; import com.pollex.pam.enums.SatisfactionTypeEnum; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; @@ -56,6 +58,10 @@ @Column(name = "appointment_id") private Long appointmentId; @Enumerated(EnumType.STRING) @Column(name = "type") private SatisfactionTypeEnum type; public Long getId() { return id; @@ -120,4 +126,12 @@ public void setAppointmentId(Long appointmentId) { this.appointmentId = appointmentId; } public SatisfactionTypeEnum getType() { return type; } public void setType(SatisfactionTypeEnum type) { this.type = type; } } pamapi/src/main/java/com/pollex/pam/repository/SatisfactionRepository.java
@@ -4,6 +4,7 @@ import java.util.Optional; import com.pollex.pam.enums.SatisfactionStatusEnum; import com.pollex.pam.enums.SatisfactionTypeEnum; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -14,15 +15,16 @@ @Repository public interface SatisfactionRepository extends JpaRepository<Satisfaction, Long>{ List<Satisfaction> findByAgentNo(String agentNo); List<Satisfaction> findByAgentNoAndType(String agentNo, SatisfactionTypeEnum type); List<Satisfaction> findByCustomerId(Long customerId); List<Satisfaction> findByCustomerIdAndType(Long customerId, SatisfactionTypeEnum type); Optional<Satisfaction> findOneByAppointmentId(Long appointmentId); List<Satisfaction> findAllByStatus(SatisfactionStatusEnum status); List<Satisfaction> findAllByStatusAndType(SatisfactionStatusEnum status, SatisfactionTypeEnum type); @Query(value = "SELECT avg(score) FROM satisfaction where agent_no=:agent_no" @Query(value = "SELECT avg(score) FROM satisfaction where type='APPOINTMENT'" + " and agent_no=:agent_no" + " and score is not null" , nativeQuery = true) Float getAgentScoreAvg(@Param("agent_no") String agentNo); pamapi/src/main/java/com/pollex/pam/service/PersonalNotificationService.java
@@ -73,7 +73,7 @@ personalNotificationRepository.save(entity); } public void createNotFillSatisfactionSumToCustomer(Long customerId, int notFillSatisfactionSum) { public void createNotFillAppointmentSatisfactionNumberToCustomer(Long customerId, int notFillSatisfactionSum) { PersonalNotification entity = new PersonalNotification(); String content = "æ¨æ "+notFillSatisfactionSum+" çé¡§åçæ»¿æåº¦éè¦å¡«å¯«"; @@ -144,7 +144,7 @@ readAllNotification(PersonalNotificationRoleEnum.CUSTOMER, SecurityUtils.getCustomerDBId()); } } public void readAllNotification(PersonalNotificationRoleEnum ownerRole , Long ownerId) { List<PersonalNotification> allNotification = personalNotificationRepository.findAllByOwnerRoleAndOwnerId(ownerRole, ownerId); pamapi/src/main/java/com/pollex/pam/service/SatisfactionService.java
@@ -4,6 +4,9 @@ import java.util.List; import java.util.Optional; import com.pollex.pam.enums.SatisfactionTypeEnum; import com.pollex.pam.security.SecurityUtils; import com.pollex.pam.service.dto.SatisfactionSystemScoreDTO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -61,17 +64,18 @@ Satisfaction satisfaction = satisfactionOP.orElseThrow(SatisfactionNotFoundException::new); satisfaction.setScore(scoreDTO.getScore()); satisfaction.setStatus(SatisfactionStatusEnum.FILLED); satisfaction.setType(SatisfactionTypeEnum.APPOINTMENT); save(satisfaction); personalNotificationService.createScorefactionToConsultant(satisfaction); return satisfaction; } public Satisfaction createSatisfaction(Appointment appointment) { public Satisfaction createAppointmentSatisfaction(Appointment appointment) { boolean isexist = getByAppointmentId(appointment.getId()).isPresent(); if(isexist) { throw new SatisfactionAlreadyExistException(); } Satisfaction satisfaction = appointmentMapper.toSatisfaction(appointment); Satisfaction satisfaction = appointmentMapper.toAppointmentSatisfaction(appointment); return save(satisfaction); } // @@ -80,13 +84,13 @@ // return save(satisfaction); // } public List<SatisfactionDTO> getByAgentNo(String agentNo) { List<Satisfaction> satisfactionList = satisfactionRepository.findByAgentNo(agentNo); public List<SatisfactionDTO> getByAgentNoAndType(String agentNo, SatisfactionTypeEnum type) { List<Satisfaction> satisfactionList = satisfactionRepository.findByAgentNoAndType(agentNo, type); return satisfactionMapper.toDTO(satisfactionList); } public List<SatisfactionDTO> getByCustomerId(Long customerDBId) { List<Satisfaction> satisfactionList = satisfactionRepository.findByCustomerId(customerDBId); public List<SatisfactionDTO> getByCustomerIdAndType(Long customerDBId, SatisfactionTypeEnum type) { List<Satisfaction> satisfactionList = satisfactionRepository.findByCustomerIdAndType(customerDBId, type); return satisfactionMapper.toDTO(satisfactionList); } @@ -94,8 +98,8 @@ return satisfactionRepository.findOneByAppointmentId(appointmentId); } public List<Satisfaction> getByStatus(SatisfactionStatusEnum status) { return satisfactionRepository.findAllByStatus(status); public List<Satisfaction> getByStatusAndType(SatisfactionStatusEnum status, SatisfactionTypeEnum type) { return satisfactionRepository.findAllByStatusAndType(status, type); } public List<Satisfaction> scoreAllfaction(List<SatisfactionCustomerScoreDTO> scoreDTO) { @@ -105,4 +109,14 @@ }); return satisfactionList; } public Satisfaction createSystemSatisfaction(SatisfactionSystemScoreDTO scoreDTO) { Satisfaction satisfaction = new Satisfaction(); satisfaction.setCustomerId(SecurityUtils.getCustomerDBId()); satisfaction.setAppointmentId(scoreDTO.getAppointmentId()); satisfaction.setStatus(SatisfactionStatusEnum.FILLED); satisfaction.setScore(scoreDTO.getScore()); satisfaction.setType(SatisfactionTypeEnum.SYSTEM); return satisfactionRepository.save(satisfaction); } } pamapi/src/main/java/com/pollex/pam/service/ScheduleTaskService.java
@@ -6,6 +6,7 @@ import com.pollex.pam.enums.AppointmentStatusEnum; import com.pollex.pam.enums.ContactStatusEnum; import com.pollex.pam.enums.SatisfactionStatusEnum; import com.pollex.pam.enums.SatisfactionTypeEnum; import com.pollex.pam.repository.AppointmentCustomerViewRepository; import com.pollex.pam.repository.AppointmentExpiringNotifyRecordRepository; import org.slf4j.Logger; @@ -127,13 +128,14 @@ // todo é確èªè©²æé, otis todo=134497 @Scheduled(cron = "0 30 8 * * *") public void sendNotFillSatisfactionToPersonalNotification() { Map<Long, List<Satisfaction>> customerNotFillSatisfactions = satisfactionService.getByStatus(SatisfactionStatusEnum.UNFILLED) public void sendNotFillAppointmentSatisfactionToPersonalNotification() { Map<Long, List<Satisfaction>> customerNotFillSatisfactions = satisfactionService.getByStatusAndType(SatisfactionStatusEnum.UNFILLED, SatisfactionTypeEnum.APPOINTMENT) .stream() .collect(Collectors.groupingBy(Satisfaction::getCustomerId)); customerNotFillSatisfactions.forEach((customerId, notFillSatisfactions) -> personalNotificationService.createNotFillSatisfactionSumToCustomer(customerId, notFillSatisfactions.size()) personalNotificationService.createNotFillAppointmentSatisfactionNumberToCustomer(customerId, notFillSatisfactions.size()) ); } pamapi/src/main/java/com/pollex/pam/service/dto/SatisfactionSystemScoreDTO.java
¤ñ¹ï·sÀÉ®× @@ -0,0 +1,23 @@ package com.pollex.pam.service.dto; public class SatisfactionSystemScoreDTO { private Long appointmentId; private Float score; public Long getAppointmentId() { return appointmentId; } public void setAppointmentId(Long appointmentId) { this.appointmentId = appointmentId; } public Float getScore() { return score; } public void setScore(Float score) { this.score = score; } } pamapi/src/main/java/com/pollex/pam/service/mapper/AppointmentMapper.java
@@ -4,6 +4,7 @@ import java.util.List; import com.pollex.pam.enums.SatisfactionTypeEnum; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -13,7 +14,6 @@ import com.pollex.pam.enums.SatisfactionStatusEnum; import com.pollex.pam.repository.AppointmentRepository; import com.pollex.pam.service.dto.AppointmentDTO; import com.pollex.pam.service.dto.SatisfactionCustomerScoreDTO; @Service public class AppointmentMapper { @@ -32,18 +32,19 @@ .map(s -> toAppointmentDTO(s)).collect(toList()); } public Satisfaction toSatisfaction(Appointment appointment) { public Satisfaction toAppointmentSatisfaction(Appointment appointment) { Satisfaction target = new Satisfaction(); target.setAppointmentId(appointment.getId()); target.setAgentNo(appointment.getAgentNo()); target.setCustomerId(appointment.getCustomerId()); target.setType(SatisfactionTypeEnum.APPOINTMENT); target.setStatus(SatisfactionStatusEnum.UNFILLED); return target; } public Satisfaction toSatisfaction(Long appointmentId) { public Satisfaction toAppointmentSatisfaction(Long appointmentId) { Appointment appointment = appointmentRepository.findById(appointmentId).get(); return toSatisfaction(appointment); return toAppointmentSatisfaction(appointment); } pamapi/src/main/java/com/pollex/pam/service/mapper/SatisfactionDTOMapper.java
@@ -9,12 +9,12 @@ @Service public class SatisfactionDTOMapper { @Autowired AppointmentMapper appointmentMapper; public Satisfaction toSatisfaction(SatisfactionCustomerScoreDTO source) { Satisfaction satisfaction = appointmentMapper.toSatisfaction(source.getAppointmentId()); Satisfaction satisfaction = appointmentMapper.toAppointmentSatisfaction(source.getAppointmentId()); satisfaction.setScore(source.getScore()); if(satisfaction.getScore()!=null) { satisfaction.setStatus(SatisfactionStatusEnum.FILLED); pamapi/src/main/java/com/pollex/pam/web/rest/SatisfactionResource.java
@@ -2,53 +2,57 @@ import java.util.List; import com.pollex.pam.enums.SatisfactionTypeEnum; import com.pollex.pam.service.dto.SatisfactionSystemScoreDTO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.pollex.pam.domain.Appointment; import com.pollex.pam.domain.Satisfaction; import com.pollex.pam.security.SecurityUtils; import com.pollex.pam.service.SatisfactionService; import com.pollex.pam.service.dto.SatisfactionCustomerScoreDTO; import com.pollex.pam.service.dto.SatisfactionDTO; import com.pollex.pam.service.dto.SatisfactionUpdateDTO; @RestController @RequestMapping("/api/satisfaction") public class SatisfactionResource { private final Logger log = LoggerFactory.getLogger(SatisfactionResource.class); @Autowired SatisfactionService satisfactionService; @PostMapping("/score") public Satisfaction scorefaction(@RequestBody SatisfactionCustomerScoreDTO scoreDTO) { return satisfactionService.scorefaction(scoreDTO); } @PostMapping("/score/all") public List<Satisfaction> scoreAllfaction(@RequestBody List<SatisfactionCustomerScoreDTO> scoreDTO) { return satisfactionService.scoreAllfaction(scoreDTO); } @GetMapping("/getMySatisfaction") public List<SatisfactionDTO> getMySatisfaction(){ if(StringUtils.hasText(SecurityUtils.getAgentNo())) { return satisfactionService.getByAgentNo(SecurityUtils.getAgentNo()); return satisfactionService.getByAgentNoAndType(SecurityUtils.getAgentNo(), SatisfactionTypeEnum.APPOINTMENT); }else if(SecurityUtils.getCustomerDBId()!=null){ return satisfactionService.getByCustomerId(SecurityUtils.getCustomerDBId()); return satisfactionService.getByCustomerIdAndType(SecurityUtils.getCustomerDBId(), SatisfactionTypeEnum.APPOINTMENT); } log.error("Not has agent code and customer id"); throw new IllegalArgumentException("Not has agent code and customer id"); } @PostMapping("/system/score") public Satisfaction createSystemSatisfaction(@RequestBody SatisfactionSystemScoreDTO scoreDTO) { return satisfactionService.createSystemSatisfaction(scoreDTO); } }