Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,10 @@ public ApiResponse<AnswerPossibleType> getAnswerPossible(@PathVariable Long surv
public ApiResponse<StatisticsSurveyResponse> getStatistics(@PathVariable Long surveyId) {
return ApiUtils.success(surveyService.getStatistics(surveyId));
}

@PostMapping("/survey/recommend/message/{surveyId}")
public ApiResponse<?> sendRecommendMessage(@PathVariable Long surveyId) {

return ApiUtils.success(surveyService.sendRecommendMessage(surveyId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.BufferedReader;
Expand Down Expand Up @@ -80,6 +79,10 @@ private String makeSignature(String url, String timestamp, String method) {

public int sendSMS(ShortMessageSendServiceRequest request) {
int responseCode = DEFAULT;
String from = request.getFrom();
if(from == null) {
from = senderPhoneNumber;
}
String timestamp = Long.toString(System.currentTimeMillis());
String hostNameUrl = "https://sens.apigw.ntruss.com";
String requestUrl = "/sms/v2/services/" + messageServiceKey + "/messages";
Expand All @@ -90,7 +93,7 @@ public int sendSMS(ShortMessageSendServiceRequest request) {
JSONArray toArr = new JSONArray();

bodyJson.put("type", request.getType().getText());
bodyJson.put("from", request.getFrom());
bodyJson.put("from", from);
bodyJson.put("content", request.getContent());

for (Message message : request.getMessages()) {
Expand Down Expand Up @@ -134,6 +137,10 @@ public int sendSMS(ShortMessageSendServiceRequest request) {

public int sendLMS(LongMessageSendServiceRequest request) {
int responseCode = DEFAULT;
String from = request.getFrom();
if(from == null) {
from = senderPhoneNumber;
}
String timestamp = Long.toString(System.currentTimeMillis());
String hostNameUrl = "https://sens.apigw.ntruss.com";
String requestUrl = "/sms/v2/services/" + messageServiceKey + "/messages";
Expand All @@ -144,7 +151,7 @@ public int sendLMS(LongMessageSendServiceRequest request) {
JSONArray toArr = new JSONArray();

bodyJson.put("type", request.getType().getText());
bodyJson.put("from", request.getFrom());
bodyJson.put("from", from);
bodyJson.put("content", request.getContent());

for (Message message : request.getMessages()) {
Expand Down Expand Up @@ -188,6 +195,10 @@ public int sendLMS(LongMessageSendServiceRequest request) {

public int sendMMS(MultimediaMessageSendServiceRequest request) {
int responseCode = DEFAULT;
String from = request.getFrom();
if(from == null) {
from = senderPhoneNumber;
}
String timestamp = Long.toString(System.currentTimeMillis());
String hostNameUrl = "https://sens.apigw.ntruss.com";
String requestUrl = "/sms/v2/services/" + messageServiceKey + "/messages";
Expand All @@ -198,7 +209,7 @@ public int sendMMS(MultimediaMessageSendServiceRequest request) {
JSONArray toArr = new JSONArray();

bodyJson.put("type", request.getType().getText());
bodyJson.put("from", request.getFrom());
bodyJson.put("from", from);
bodyJson.put("content", request.getContent());
bodyJson.put("subject", request.getSubject());

Expand All @@ -211,11 +222,11 @@ public int sendMMS(MultimediaMessageSendServiceRequest request) {
}

JSONArray fileArr = new JSONArray();
for (String fileId : request.getFiles()) {
JSONObject fileIdJson = new JSONObject();
fileIdJson.put("fileId", fileId);
fileArr.add(fileIdJson);
}
String fileId = this.registImageToNCP(request.getFileName() , request.getFileBody());

JSONObject fileIdJson = new JSONObject();
fileIdJson.put("fileId", fileId);
fileArr.add(fileIdJson);
bodyJson.put("files", fileArr);

bodyJson.put("messages", toArr);
Expand Down Expand Up @@ -324,7 +335,6 @@ public ShortMessageSendServiceRequest makeCertMessage(String phoneNumber) {
);
ShortMessageSendServiceRequest request =
ShortMessageSendServiceRequest.builder()
.from(senderPhoneNumber)
.messages(messages)
.content("회원가입 인증 공통 문자")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ public class MultimediaMessageSendServiceRequest {
private String content;
List<Message> messages;
private String subject;
List<String> files;
String fileName;
String fileBody;

@Builder
MultimediaMessageSendServiceRequest( String from , String content , List<Message> messages , String subject , List<String> files) {
MultimediaMessageSendServiceRequest( String from , String content , List<Message> messages , String subject , String fileName,
String fileBody) {
this.type = MessageType.MULTIMEDIAMESSAGE;
this.from = from;
this.content = content;
this.messages = messages;
this.subject = subject;
this.files = files;
this.fileName = fileName;
this.fileBody = fileBody;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ public class ShortMessageSendServiceRequest {
List<Message> messages;

@Builder
ShortMessageSendServiceRequest(String from , String content , List<Message> messages ) {
ShortMessageSendServiceRequest(String content , List<Message> messages ) {
this.type = MessageType.SHORTMESSAGE;
this.from = from;
this.content = content;
this.messages = messages;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


import com.logwiki.specialsurveyservice.api.service.account.AccountService;
import com.logwiki.specialsurveyservice.api.service.message.MessageService;
import com.logwiki.specialsurveyservice.api.service.message.request.ShortMessageSendServiceRequest;
import com.logwiki.specialsurveyservice.api.service.question.response.QuestionAnswerStatisticsResponse;
import com.logwiki.specialsurveyservice.api.service.sse.response.SurveyAnswerResponse;
import com.logwiki.specialsurveyservice.api.service.survey.request.GiveawayAssignServiceRequest;
Expand All @@ -19,6 +21,7 @@
import com.logwiki.specialsurveyservice.domain.accountsurvey.AccountSurvey;
import com.logwiki.specialsurveyservice.domain.accountsurvey.AccountSurveyRepository;
import com.logwiki.specialsurveyservice.domain.giveaway.GiveawayRepository;
import com.logwiki.specialsurveyservice.domain.message.Message;
import com.logwiki.specialsurveyservice.domain.multiplechoice.MultipleChoice;
import com.logwiki.specialsurveyservice.domain.multiplechoice.MultipleChoiceRepository;
import com.logwiki.specialsurveyservice.domain.question.Question;
Expand Down Expand Up @@ -68,6 +71,7 @@ public class SurveyService {
private final AccountSurveyRepository accountSurveyRepository;
private final QuestionAnswerRepository questionAnswerRepository;
private final MultipleChoiceRepository multipleChoiceRepository;
private final MessageService messageService;

private static final String LOSEPRODUCT = "꽝";
private static final boolean HIDDEN_BOOLEAN_RESULT = false;
Expand Down Expand Up @@ -462,4 +466,27 @@ else if((questionType == QuestionCategoryType.SHORT_FORM)

return questionAnswerResponse;
}

public Boolean sendRecommendMessage(Long surveyId) {
SurveyResponse surveyResponse = this.getSurvey(surveyId);
List<Account> accounts = accountRepository.findRecommendAccounts(surveyId);
if(accounts.size() == 0) {
throw new BaseException("추천대상이 존재하지 않습니다." , 8006);
}
List<Message> messages = new ArrayList<>();
for(Account account : accounts) {
messages.add(Message.builder().to(account.getPhoneNumber().replaceAll("-","")).build());
log.info(account.getName() + " " + account.getGender() + " " + account.getAge());
}

ShortMessageSendServiceRequest messageRequest = new ShortMessageSendServiceRequest();
messageService.sendSMS(ShortMessageSendServiceRequest.builder()
.content("설문 추천 드려요!!!! \n"
+ "i9e107.p.ssafy.io/surveydetail/"
+ surveyId )
.messages(messages)
.build());

return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.logwiki.specialsurveyservice.domain.account;

import com.logwiki.specialsurveyservice.domain.survey.Survey;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
Expand All @@ -13,4 +17,16 @@ public interface AccountRepository extends JpaRepository<Account, Long> {

@EntityGraph(attributePaths = "authorities")
Optional<Account> findOneWithAuthoritiesByPhoneNumber(String phoneNumber);

@Query(value = "SELECT * FROM account acc "
+ "WHERE (SELECT ac.ID FROM ACCOUNT_CODE ac WHERE ac.TYPE = acc.gender) IN (SELECT st.ACCOUNT_CODE_ID "
+ "FROM SURVEY_TARGET st "
+ "WHERE st.SURVEY_ID = :surveyId)"
+ "AND (SELECT ac.ID FROM ACCOUNT_CODE ac WHERE ac.TYPE = acc.age) IN (SELECT st.ACCOUNT_CODE_ID "
+ "FROM SURVEY_TARGET st "
+ "WHERE st.SURVEY_ID = :surveyId)"
,
nativeQuery = true)
List<Account> findRecommendAccounts(@Param("surveyId") Long surveyId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ void sendSMSTest() {
ShortMessageSendServiceRequest request =
ShortMessageSendServiceRequest.builder()
.messages(messages)
.from("01055014037")
.content("테스트보내기")
.build();

Expand Down Expand Up @@ -94,21 +93,23 @@ void registImageTest() {
}
}
}
String fileID = messageService.registImageToNCP("더미치킨.jpg",fileBody);
System.out.println(fileBody);
// String fileID = messageService.registImageToNCP("더미치킨.jpg",fileBody);

Message mms = Message.builder()
.to("01055014037")
.subject("연재용 MMS 제목")
.content("연재용 MMS 내용")
.build();
List<Message> messages = new ArrayList<>();
messages.add(mms);
List<String> fileNames = new ArrayList<>();
fileNames.add(fileID);

int responseCode = messageService.sendMMS(MultimediaMessageSendServiceRequest.builder()
.from("01055014037")
.content("공통MMS내용")
.messages(messages)
.files(fileNames)
.fileName("더미치킨.jpg")
.fileBody(fileBody)
.subject("공통 MMS 주제")
.build());
assertThat(responseCode).isEqualTo(202);
Expand Down