调查问卷查看
This commit is contained in:
@@ -0,0 +1,217 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import com.ai.da.common.constant.CommonConstant;
|
||||
import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.mapper.primary.QuestionnaireMapper;
|
||||
import com.ai.da.mapper.primary.entity.Account;
|
||||
import com.ai.da.mapper.primary.entity.Questionnaire;
|
||||
import com.ai.da.model.vo.QuestionnaireFeedbackVO;
|
||||
import com.ai.da.model.vo.QuestionnaireVO;
|
||||
import com.ai.da.service.AccountService;
|
||||
import com.ai.da.service.ConvenientInquiryService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.itextpdf.text.DocumentException;
|
||||
import com.itextpdf.text.Font;
|
||||
import com.itextpdf.text.pdf.BaseFont;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.itextpdf.text.Document;
|
||||
import com.itextpdf.text.Paragraph;
|
||||
import com.itextpdf.text.pdf.PdfWriter;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ConvenientInquiryServiceImpl extends ServiceImpl<QuestionnaireMapper, Questionnaire> implements ConvenientInquiryService {
|
||||
|
||||
@Resource
|
||||
private AccountService accountService;
|
||||
|
||||
|
||||
public QuestionnaireFeedbackVO getQuestionnaireInfo() {
|
||||
String title = "AiDA_3.0 Feedback Survey--06/2024";
|
||||
List<Questionnaire> questionnaires = queryByTitle(title);
|
||||
List<Integer> ageValue = new ArrayList<>(Collections.nCopies(4, 0));
|
||||
List<Integer> question1Value = new ArrayList<>(Collections.nCopies(12, 0));
|
||||
List<Integer> question2Value = new ArrayList<>(Collections.nCopies(11, 0));
|
||||
List<Integer> question3Value = new ArrayList<>(Collections.nCopies(2, 0));
|
||||
List<String> question4Value = new ArrayList<>();
|
||||
ArrayList<String> othersReason1 = new ArrayList<>();
|
||||
ArrayList<String> othersReason2 = new ArrayList<>();
|
||||
ArrayList<String> othersReason3 = new ArrayList<>();
|
||||
|
||||
for (Questionnaire questionnaire : questionnaires) {
|
||||
QuestionnaireVO questionnaireVO = JSON.parseObject(questionnaire.getQuestionnaireInfo(), QuestionnaireVO.class);
|
||||
// 统计年龄区间
|
||||
String age = questionnaireVO.getAge();
|
||||
if (age.contains("20-30")) {
|
||||
Integer num = ageValue.get(1);
|
||||
ageValue.set(1, ++num);
|
||||
} else if (age.contains("30-40")) {
|
||||
Integer num = ageValue.get(2);
|
||||
ageValue.set(2, ++num);
|
||||
} else if (age.contains("40+")) {
|
||||
Integer num = ageValue.get(3);
|
||||
ageValue.set(3, ++num);
|
||||
} else {
|
||||
Integer num = ageValue.get(0);
|
||||
ageValue.set(0, ++num);
|
||||
}
|
||||
|
||||
// How has AiDA been helpful to you? 统计
|
||||
List<String> helpful = questionnaireVO.getHelpful();
|
||||
helpful.forEach(item -> {
|
||||
if (item.matches("\\d+")) {
|
||||
Integer num = question1Value.get(Integer.parseInt(item) - 1);
|
||||
question1Value.set(Integer.parseInt(item) - 1, ++num);
|
||||
} else {
|
||||
Integer num = question1Value.get(11);
|
||||
question1Value.set(11, ++num);
|
||||
othersReason1.add(item);
|
||||
}
|
||||
});
|
||||
|
||||
// What do you think AiDA should improve? 统计
|
||||
List<String> improve = questionnaireVO.getImprove();
|
||||
improve.forEach(item -> {
|
||||
if (item.matches("\\d+")) {
|
||||
Integer num = question2Value.get(Integer.parseInt(item) - 1);
|
||||
question2Value.set(Integer.parseInt(item) - 1, ++num);
|
||||
} else {
|
||||
Integer num = question2Value.get(10);
|
||||
question2Value.set(10, ++num);
|
||||
othersReason2.add(item);
|
||||
}
|
||||
});
|
||||
|
||||
// Will you subscribe to AiDA 3.0?
|
||||
String isSubscribe = questionnaireVO.getIsSubscribe();
|
||||
if (isSubscribe.equals("yes")) {
|
||||
Integer num = question3Value.get(0);
|
||||
question3Value.set(0, ++num);
|
||||
} else {
|
||||
Integer num = question3Value.get(1);
|
||||
question3Value.set(1, ++num);
|
||||
othersReason3.add(String.join(",", questionnaireVO.getReasonForNotSubscribe()));
|
||||
}
|
||||
if (!StringUtil.isNullOrEmpty(questionnaireVO.getDesignTools())) {
|
||||
question4Value.add(questionnaireVO.getDesignTools());
|
||||
}
|
||||
}
|
||||
|
||||
String language = UserContext.getUserHolder().getLanguage();
|
||||
List<String> ageName;
|
||||
List<String> question1Name;
|
||||
List<String> question2Name;
|
||||
if (language.equals("English")) {
|
||||
ageName = CommonConstant.AGES_EN;
|
||||
question1Name = CommonConstant.IF_HELPFUL_EN;
|
||||
question2Name = CommonConstant.IF_IMPROVE_EN;
|
||||
} else {
|
||||
ageName = CommonConstant.AGES_CN;
|
||||
question1Name = CommonConstant.IF_HELPFUL_CN;
|
||||
question2Name = CommonConstant.IF_IMPROVE_CN;
|
||||
}
|
||||
return new QuestionnaireFeedbackVO(
|
||||
new QuestionnaireFeedbackVO.Info(ageName, ageValue),
|
||||
new QuestionnaireFeedbackVO.Info(question1Name, question1Value, othersReason1),
|
||||
new QuestionnaireFeedbackVO.Info(question2Name, question2Value, othersReason2),
|
||||
new QuestionnaireFeedbackVO.Info(CommonConstant.IS_SUBSCRIBE, question3Value, othersReason3),
|
||||
question4Value
|
||||
);
|
||||
}
|
||||
|
||||
private List<Questionnaire> queryByTitle(String title) {
|
||||
QueryWrapper<Questionnaire> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("title", title);
|
||||
return baseMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
public List<QuestionnaireVO> getAllQuestionnaire() {
|
||||
String title = "AiDA_3.0 Feedback Survey--06/2024";
|
||||
List<Questionnaire> questionnaires = queryByTitle(title);
|
||||
ArrayList<QuestionnaireVO> questionnaireVOS = new ArrayList<>();
|
||||
|
||||
questionnaires.forEach(item -> {
|
||||
QuestionnaireVO questionnaireVO = JSON.parseObject(item.getQuestionnaireInfo(), QuestionnaireVO.class);
|
||||
questionnaireVOS.add(questionnaireVO);
|
||||
}
|
||||
);
|
||||
|
||||
return questionnaireVOS;
|
||||
}
|
||||
|
||||
|
||||
// 输出为pdf 需要自己组装pdf内容
|
||||
// 解决iText不显示中文问题
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// 创建文档
|
||||
Document document = new Document();
|
||||
PdfWriter.getInstance(document, new FileOutputStream("output.pdf"));
|
||||
document.open();
|
||||
|
||||
// 加载字体文件
|
||||
InputStream inputStream = ConvenientInquiryServiceImpl.class.getResourceAsStream("/font/msyhl.ttc");
|
||||
byte[] fontBytes = toByteArray(inputStream);
|
||||
inputStream.close();
|
||||
|
||||
// 创建BaseFont和Font对象
|
||||
BaseFont baseFont = BaseFont.createFont("msyhl.ttc,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, true, fontBytes, null);
|
||||
Font yaHeiFont = new Font(baseFont, 12, Font.NORMAL);
|
||||
|
||||
// 添加带有中文字体的段落
|
||||
document.add(new Paragraph("你好,世界!", yaHeiFont));
|
||||
|
||||
document.close();
|
||||
} catch (DocumentException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 将InputStream转换为字节数组
|
||||
public static byte[] toByteArray(InputStream input) throws IOException {
|
||||
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[1024];
|
||||
int n = 0;
|
||||
while (-1 != (n = input.read(buffer))) {
|
||||
output.write(buffer, 0, n);
|
||||
}
|
||||
return output.toByteArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 近期新增用户
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @param userType 用户类型 visitor\trial\official
|
||||
* @return
|
||||
*/
|
||||
public List<Account> recentNewUser(String startTime, String endTime, String userType){
|
||||
if (StringUtil.isNullOrEmpty(startTime) && StringUtil.isNullOrEmpty(endTime) && StringUtil.isNullOrEmpty(userType)){
|
||||
return null;
|
||||
}
|
||||
|
||||
int type = userType.equals("visitor") ? 0 : userType.equals("trial") ? 1 : 2;
|
||||
return accountService.getByDateAndUserType(startTime, endTime, type);
|
||||
}
|
||||
|
||||
// 近期活跃用户
|
||||
public List<Account> recentActiveUser(String startTime, String endTime){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user