Skip to content

Commit

Permalink
[Feature] 新增问卷发布功能 (#372)
Browse files Browse the repository at this point in the history
* feat: 1,添加修改问卷,删除问卷接口,修改创建问卷 部分逻辑
2,添加修改问卷,删除问卷接口单元测试

* feat: 1,添加修改问卷,删除问卷接口,修改创建问卷 部分逻辑
2,添加修改问卷,删除问卷接口单元测试

* style:代码格式化调整

* style:代码格式化调整

* feat:新增发布问卷接口,同时修改了创建问卷接口

---------

Co-authored-by: kui <[email protected]>
  • Loading branch information
likui63 and kui authored Jul 30, 2024
1 parent ad42623 commit c52a6dd
Show file tree
Hide file tree
Showing 15 changed files with 337 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.compiler.source.version>1.8</java.compiler.source.version>
<java.compiler.target.version>1.8</java.compiler.target.version>
<lombok.version>1.18.8</lombok.version>
<lombok.version>1.18.20</lombok.version>
<junit.version>4.12</junit.version>
<lang3.version>3.14.0</lang3.version>
<fastjson.version>1.2.83</fastjson.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum RespErrorCode {
SURVEY_CONTENT_NOT_ALLOW(3005, "存在禁用内容"),
UPDATE_SURVEY_META_ERROR(3006, "修改问卷失败"),
DELETE_SURVEY_ERROR(3007, "删除问卷失败"),
PUBLISH_SURVEY_ERROR(3008, "发布问卷失败"),
CAPTCHA_INCORRECT(4001, "验证码不正确"),
RESPONSE_SIGN_ERROR(9001, "签名不正确"),
RESPONSE_CURRENT_TIME_NOT_ALLOW(9002, "当前时间不允许提交"),
Expand All @@ -27,8 +28,6 @@ public enum RespErrorCode {
UPLOAD_FILE_ERROR(5001, "上传文件错误");




private final int code;
private final String message;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Map;

/**
* 问卷发布后的配置表
*
* @author [email protected]
* @date: 2024/7/27 13:59
*/
@Document("surveySubmit")
@Document("surveyPublish")
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Data
Expand Down Expand Up @@ -45,7 +46,7 @@ public class SurveyPublish extends BaseEntity {
*/
@NotBlank(message = "问卷schema不能为空")
@NotNull(message = "问卷schema不能为空")
private String code;
private Map<String, Object> code;


}
6 changes: 6 additions & 0 deletions survey-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>4.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import com.xiaojusurvey.engine.common.entity.survey.SurveyConf;


public interface SurveyConfService {

void createSurveyConf(SurveyConf surveyConf);

void saveSurveyConfig(SurveyConf surveyConf);

SurveyConf getSurveyConfBySurveyId(String surveyId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.xiaojusurvey.engine.core.survey;

import com.xiaojusurvey.engine.common.entity.survey.SurveyMeta;
import com.xiaojusurvey.engine.common.entity.survey.SurveyPublish;

/**
* 问卷发布配置服务
Expand All @@ -10,6 +11,9 @@
*/
public interface SurveyPublishService {

boolean save(SurveyPublish surveyPublish);

boolean delete(SurveyMeta param);

SurveyPublish getByPageId(String surveyId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,15 @@ public interface SurveyService {
boolean updateMeta(SurveyMetaUpdateParam param);

boolean deleteSurvey(String surveyId);

/**
* 发布问卷
*
* @param surveyId
* @return
*/
boolean publishSurvey(String surveyId);



}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public class SurveyConfServiceImpl implements SurveyConfService {
@Resource
private MongoRepository mongoRepository;

@Override
public void createSurveyConf(SurveyConf surveyConf) {
mongoRepository.save(surveyConf);
}

@Override
public void saveSurveyConfig(SurveyConf surveyConf) {
SurveyConf codeInfo = this.getSurveyConfBySurveyId(surveyConf.getPageId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public void setMongoRepository(MongoRepository mongoRepository) {
}


@Override
public boolean save(SurveyPublish surveyPublish) {
SurveyPublish ret = mongoRepository.save(surveyPublish);
return true;
}

@Override
public boolean delete(SurveyMeta param) {
if (StringUtils.hasLength(param.getSurveyPath())) {
Expand All @@ -47,6 +53,14 @@ public boolean delete(SurveyMeta param) {
return true;
}

@Override
public SurveyPublish getByPageId(String surveyId) {
Query query = new Query();
query.addCriteria(Criteria.where("pageId").is(surveyId));
SurveyPublish surveyPublish = mongoRepository.findOne(query, SurveyPublish.class);
return surveyPublish;
}

public SurveyPublish getBysurveyPath(String surveyPath) {
Query query = new Query();
query.addCriteria(Criteria.where("surveyPath").is(surveyPath));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
package com.xiaojusurvey.engine.core.survey.impl;

import java.util.ArrayList;

import com.xiaojusurvey.engine.common.constants.RespErrorCode;
import com.xiaojusurvey.engine.common.entity.Status;
import com.xiaojusurvey.engine.common.entity.survey.SurveyConf;
import com.xiaojusurvey.engine.common.entity.survey.SurveyHistory;
import com.xiaojusurvey.engine.common.entity.survey.SurveyMeta;
import com.xiaojusurvey.engine.common.entity.survey.SurveyPublish;
import com.xiaojusurvey.engine.common.entity.user.User;
import com.xiaojusurvey.engine.common.enums.HistoryTypeEnum;
import com.xiaojusurvey.engine.common.enums.SurveyStatusEnum;
import com.xiaojusurvey.engine.common.exception.ServiceException;
import com.xiaojusurvey.engine.core.reslut.IdResult;
import com.xiaojusurvey.engine.core.survey.SurveyConfService;
import com.xiaojusurvey.engine.core.survey.SurveyHistoryService;
import com.xiaojusurvey.engine.core.survey.SurveyPublishService;
import com.xiaojusurvey.engine.core.survey.SurveyService;
import com.xiaojusurvey.engine.core.survey.param.SurveyMetaUpdateParam;
import com.xiaojusurvey.engine.core.util.WebUtils;
import com.xiaojusurvey.engine.repository.MongoRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.query.Criteria;
Expand All @@ -18,7 +28,9 @@

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @Author: LYF
Expand All @@ -35,6 +47,12 @@ public class SurveyServiceImpl implements SurveyService {
@Resource
private SurveyPublishService surveyPublishService;

@Resource
private SurveyConfService surveyConfService;

@Resource
private SurveyHistoryService surveyHistoryService;

public MongoRepository getMongoRepository() {
return mongoRepository;
}
Expand All @@ -54,6 +72,17 @@ public IdResult createSurvey(SurveyMeta surveyMeta) {
List<Status> statusList = Arrays.asList(newStatus);
surveyMeta.setStatusList(statusList);
idResult.setId(mongoRepository.save(surveyMeta).getId());
//保存survyConf
SurveyConf conf = new SurveyConf();
conf.setPageId(idResult.getId());
Map map = new HashMap<>(4);
conf.setCode(map);
// conf.setId("");
// conf.setCreateDate(0L);
// conf.setUpdateDate(0L);
conf.setCurStatus(new Status());
conf.setStatusList(new ArrayList<Status>());
surveyConfService.createSurveyConf(conf);
return idResult;
}

Expand Down Expand Up @@ -104,5 +133,47 @@ public boolean deleteSurvey(String surveyId) {
return true;
}

@Override
public boolean publishSurvey(String surveyId) {
//1,查询问卷配置
SurveyConf conf = surveyConfService.getSurveyConfBySurveyId(surveyId);
SurveyMeta meta = getSurveyMeta(surveyId);
//2,surveyMeta保存
Status pub = SurveyStatusEnum.getSpecStatus(SurveyStatusEnum.PUBLISHED);
meta.setCurStatus(pub);
meta.getStatusList().add(pub);
mongoRepository.save(meta);

//3,保存问卷配置到publish表
SurveyPublish publish = new SurveyPublish();
publish.setPageId(surveyId);
publish.setTitle(meta.getTitle());
publish.setSurveyPath(meta.getSurveyPath());
publish.setCode(conf.getCode());
// publish.setId("");
// publish.setCreateDate(0L);
// publish.setUpdateDate(0L);
// Status pub = SurveyStatusEnum.getSpecStatus(SurveyStatusEnum.PUBLISHED);
publish.setCurStatus(pub);
publish.setStatusList(Arrays.asList(pub));
surveyPublishService.save(publish);

//4,保存history
SurveyHistory his = new SurveyHistory();
his.setPageId(conf.getId());
his.setSchema(conf.getCode());
his.setType(HistoryTypeEnum.PUBLISH_HIS.getHistoryType());
User user = (User) WebUtils.getHttpServletRequest().getAttribute("user");
Map<String, Object> opt = new HashMap<>(4);
opt.put("_id", user.getId());
opt.put("username", user.getUsername());
his.setOperator(opt);
Status st = SurveyStatusEnum.getSpecStatus(SurveyStatusEnum.NEW);
his.setCurStatus(st);
his.setStatusList(Arrays.asList(st));
surveyHistoryService.addHistory(his);
return true;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//package com.xiaojusurvey.engine.core.survey.vo;
//
//import com.xiaojusurvey.engine.common.entity.Status;
//
//import javax.validation.constraints.NotBlank;
//import javax.validation.constraints.NotNull;
//
///**
// * 问卷信息
// *
// * @author [email protected]
// * @Date 2024/7/28 21:57
// */
//public class SurveyVO {
//
// private String _id;
//
// private String name;
// /**
// * 问卷类型
// */
// @NotBlank(message = "问卷类型不能为空")
// @NotNull(message = "问卷类型不能为空")
// private String surveyType;
//
// /**
// * 问卷短链
// */
// private String surveyPath;
// /**
// * 问卷标题
// */
// private String title;
// /**
// * 当前状态
// */
// private Status curStatus;
//
// /**
// * 创建时间
// */
// private Long createDate;
//
// /**
// * 创建人
// */
// private String creator;
// /**
// * 所有者
// */
// private String owner;
//
//}
Loading

0 comments on commit c52a6dd

Please sign in to comment.