diff --git a/pom.xml b/pom.xml
index c20bf656..9c93b1fd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,7 +29,7 @@
UTF-8
1.8
1.8
- 1.18.8
+ 1.18.20
4.12
3.14.0
1.2.83
diff --git a/survey-common/src/main/java/com/xiaojusurvey/engine/common/constants/RespErrorCode.java b/survey-common/src/main/java/com/xiaojusurvey/engine/common/constants/RespErrorCode.java
index cd4420d7..6ddec6a5 100644
--- a/survey-common/src/main/java/com/xiaojusurvey/engine/common/constants/RespErrorCode.java
+++ b/survey-common/src/main/java/com/xiaojusurvey/engine/common/constants/RespErrorCode.java
@@ -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, "当前时间不允许提交"),
@@ -27,8 +28,6 @@ public enum RespErrorCode {
UPLOAD_FILE_ERROR(5001, "上传文件错误");
-
-
private final int code;
private final String message;
diff --git a/survey-common/src/main/java/com/xiaojusurvey/engine/common/entity/survey/SurveyPublish.java b/survey-common/src/main/java/com/xiaojusurvey/engine/common/entity/survey/SurveyPublish.java
index 910fd550..ee44c63f 100644
--- a/survey-common/src/main/java/com/xiaojusurvey/engine/common/entity/survey/SurveyPublish.java
+++ b/survey-common/src/main/java/com/xiaojusurvey/engine/common/entity/survey/SurveyPublish.java
@@ -8,6 +8,7 @@
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
+import java.util.Map;
/**
* 问卷发布后的配置表
@@ -15,7 +16,7 @@
* @author likui63@163.com
* @date: 2024/7/27 13:59
*/
-@Document("surveySubmit")
+@Document("surveyPublish")
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Data
@@ -45,7 +46,7 @@ public class SurveyPublish extends BaseEntity {
*/
@NotBlank(message = "问卷schema不能为空")
@NotNull(message = "问卷schema不能为空")
- private String code;
+ private Map code;
}
diff --git a/survey-core/pom.xml b/survey-core/pom.xml
index c37d2d48..f565025c 100644
--- a/survey-core/pom.xml
+++ b/survey-core/pom.xml
@@ -43,6 +43,12 @@
junit
test
+
+ org.mockito
+ mockito-inline
+ 4.3.0
+ test
+
diff --git a/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/SurveyConfService.java b/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/SurveyConfService.java
index 35cdf3a6..bfcc9870 100644
--- a/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/SurveyConfService.java
+++ b/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/SurveyConfService.java
@@ -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);
diff --git a/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/SurveyPublishService.java b/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/SurveyPublishService.java
index b7b5a186..7c8eeac6 100644
--- a/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/SurveyPublishService.java
+++ b/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/SurveyPublishService.java
@@ -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;
/**
* 问卷发布配置服务
@@ -10,6 +11,9 @@
*/
public interface SurveyPublishService {
+ boolean save(SurveyPublish surveyPublish);
boolean delete(SurveyMeta param);
+
+ SurveyPublish getByPageId(String surveyId);
}
diff --git a/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/SurveyService.java b/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/SurveyService.java
index 2688d7f6..94c8a217 100644
--- a/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/SurveyService.java
+++ b/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/SurveyService.java
@@ -17,4 +17,15 @@ public interface SurveyService {
boolean updateMeta(SurveyMetaUpdateParam param);
boolean deleteSurvey(String surveyId);
+
+ /**
+ * 发布问卷
+ *
+ * @param surveyId
+ * @return
+ */
+ boolean publishSurvey(String surveyId);
+
+
+
}
diff --git a/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/impl/SurveyConfServiceImpl.java b/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/impl/SurveyConfServiceImpl.java
index 3e78a326..9dd4aa38 100644
--- a/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/impl/SurveyConfServiceImpl.java
+++ b/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/impl/SurveyConfServiceImpl.java
@@ -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());
diff --git a/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/impl/SurveyPublishServiceImpl.java b/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/impl/SurveyPublishServiceImpl.java
index da6f8835..1e265456 100644
--- a/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/impl/SurveyPublishServiceImpl.java
+++ b/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/impl/SurveyPublishServiceImpl.java
@@ -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())) {
@@ -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));
diff --git a/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/impl/SurveyServiceImpl.java b/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/impl/SurveyServiceImpl.java
index 47c204c5..cfd80387 100644
--- a/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/impl/SurveyServiceImpl.java
+++ b/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/impl/SurveyServiceImpl.java
@@ -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;
@@ -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
@@ -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;
}
@@ -54,6 +72,17 @@ public IdResult createSurvey(SurveyMeta surveyMeta) {
List 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());
+ surveyConfService.createSurveyConf(conf);
return idResult;
}
@@ -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 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;
+ }
+
}
diff --git a/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/vo/SurveyVO.java b/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/vo/SurveyVO.java
new file mode 100644
index 00000000..571c004b
--- /dev/null
+++ b/survey-core/src/main/java/com/xiaojusurvey/engine/core/survey/vo/SurveyVO.java
@@ -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 likui63@163.com
+// * @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;
+//
+//}
diff --git a/survey-core/src/main/java/com/xiaojusurvey/engine/core/util/WebUtils.java b/survey-core/src/main/java/com/xiaojusurvey/engine/core/util/WebUtils.java
new file mode 100644
index 00000000..378a2337
--- /dev/null
+++ b/survey-core/src/main/java/com/xiaojusurvey/engine/core/util/WebUtils.java
@@ -0,0 +1,97 @@
+package com.xiaojusurvey.engine.core.util;
+
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/**
+ * @author likui63@163.com
+ * @Date 2024/7/30 19:15
+ */
+public class WebUtils {
+
+ private static final String LOCALHOST = "127.0.0.1";
+ private static final String DOT = ".";
+ private static final int IP_LEN_0 = 0;
+ private static final int IP_LEN_15 = 15;
+ private static final String HEADER_X_FORWARDED_FOR = "x-forwarded-for";
+ private static final String HEADER_PROXY_CLIENT_IP = "Proxy-Client-IP";
+ private static final String HEADER_WL_PROXY_CLIENT_IP = "WL-Proxy-Client-IP";
+ private static final String UNKNOWN = "unknown";
+
+
+ public static ServletRequestAttributes getServletRequestAttributes() {
+ return (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+ }
+
+ /**
+ * 得到当前线程的请求对象
+ *
+ * @return
+ */
+ public static HttpServletRequest getHttpServletRequest() {
+ return getServletRequestAttributes().getRequest();
+ }
+
+ /**
+ * 得到访问的ip地址
+ *
+ * @return
+ */
+ public static String getRequestIp() {
+ HttpServletRequest request = getHttpServletRequest();
+ String ip = null;
+ ip = request.getHeader(HEADER_X_FORWARDED_FOR);
+ if ((ip == null) || (ip.length() == IP_LEN_0) || (UNKNOWN.equalsIgnoreCase(ip))) {
+ ip = request.getHeader(HEADER_PROXY_CLIENT_IP);
+ }
+ if ((ip == null) || (ip.length() == IP_LEN_0) || (UNKNOWN.equalsIgnoreCase(ip))) {
+ ip = request.getHeader(HEADER_WL_PROXY_CLIENT_IP);
+ }
+ if ((ip == null) || (ip.length() == IP_LEN_0) || (UNKNOWN.equalsIgnoreCase(ip))) {
+ ip = request.getRemoteAddr();
+ if (LOCALHOST.equals(ip)) {
+ InetAddress inet = null;
+ try {
+ inet = InetAddress.getLocalHost();
+ } catch (UnknownHostException e) {
+ e.printStackTrace();
+ }
+ ip = inet.getHostAddress();
+ }
+ }
+ if ((ip != null) && (ip.length() > IP_LEN_15)) {
+ if (ip.indexOf(DOT) > IP_LEN_0) {
+ ip = ip.substring(IP_LEN_0, ip.indexOf(","));
+ }
+ }
+ return ip;
+ }
+
+ /**
+ * 得到当前线程的响应对象
+ */
+ public static HttpServletResponse getHttpServletResponse() {
+ return getServletRequestAttributes().getResponse();
+ }
+
+ /**
+ * 得到session对象
+ */
+ public static HttpSession getHttpSession() {
+ return getHttpServletRequest().getSession();
+ }
+
+ /**
+ * 得到servletContext对象
+ */
+ public static ServletContext getServletContext() {
+ return getHttpServletRequest().getServletContext();
+ }
+}
diff --git a/survey-core/src/test/java/com/xiaojusurvey/engine/core/survey/impl/SurveyServiceImplTest.java b/survey-core/src/test/java/com/xiaojusurvey/engine/core/survey/impl/SurveyServiceImplTest.java
index 2f747557..8f8558ff 100644
--- a/survey-core/src/test/java/com/xiaojusurvey/engine/core/survey/impl/SurveyServiceImplTest.java
+++ b/survey-core/src/test/java/com/xiaojusurvey/engine/core/survey/impl/SurveyServiceImplTest.java
@@ -2,24 +2,31 @@
import com.xiaojusurvey.engine.common.entity.Status;
+import com.xiaojusurvey.engine.common.entity.survey.SurveyConf;
import com.xiaojusurvey.engine.common.entity.survey.SurveyMeta;
+import com.xiaojusurvey.engine.common.entity.user.User;
import com.xiaojusurvey.engine.common.enums.SurveyStatusEnum;
+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.param.SurveyMetaUpdateParam;
+import com.xiaojusurvey.engine.core.util.WebUtils;
import com.xiaojusurvey.engine.repository.MongoRepository;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.junit.platform.engine.TestTag;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.when;
/**
* 问卷service单元测试
@@ -36,6 +43,12 @@ public class SurveyServiceImplTest {
@Mock
SurveyPublishService surveyPublishService;
+ @Mock
+ SurveyConfService surveyConfService;
+
+ @Mock
+ SurveyHistoryService surveyHistoryService;
+
@Mock
MongoRepository mongoRepository;
@@ -67,7 +80,7 @@ public void updateMetaTest() {
updateParam.setTitle("新时代");
updateParam.setRemark("这是一个测试");
- when(mongoRepository.findOne(any(),any())).thenReturn(surveyMeta);
+ Mockito.when(mongoRepository.findOne(Mockito.any(),Mockito.any())).thenReturn(surveyMeta);
boolean flag = surveyService.updateMeta(updateParam);
Assert.assertEquals(true,flag);
@@ -77,11 +90,32 @@ public void updateMetaTest() {
@Test
public void deleteSurveyTest() {
- when(mongoRepository.findOne(any(),any())).thenReturn(surveyMeta);
- when(surveyPublishService.delete(any())).thenReturn(true);
+ Mockito.when(mongoRepository.findOne(Mockito.any(),Mockito.any())).thenReturn(surveyMeta);
+ Mockito.when(surveyPublishService.delete(Mockito.any())).thenReturn(true);
boolean flag = surveyService.deleteSurvey(surveyid);
Assert.assertEquals(true,flag);
+ }
+
+ @Test
+ public void publishSurveyTest(){
+ SurveyConf conf = new SurveyConf();
+
+ Mockito.when(surveyConfService.getSurveyConfBySurveyId(Mockito.any())).thenReturn(conf);
+ Mockito.when(mongoRepository.findOne(Mockito.any(),Mockito.eq(SurveyMeta.class))).thenReturn(surveyMeta);
+ Mockito.when(mongoRepository.save(Mockito.any())).thenReturn(null);
+ Mockito.when(surveyPublishService.save(Mockito.any())).thenReturn(true);
+ Mockito.when(surveyHistoryService.addHistory(Mockito.any())).thenReturn(null);
+ Mockito.mockStatic(WebUtils.class);
+ HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
+ Mockito.when(WebUtils.getHttpServletRequest()).thenReturn(req);
+ User user = new User();
+ user.setId("123");
+ user.setUsername("ttt");
+ Mockito.when(req.getAttribute("user")).thenReturn(user);
+ boolean falg = surveyService.publishSurvey(surveyid);
+ Assert.assertTrue("成功",falg == true);
}
+
}
\ No newline at end of file
diff --git a/survey-server/src/main/java/com/xiaojusurvey/engine/controller/SurveyController.java b/survey-server/src/main/java/com/xiaojusurvey/engine/controller/SurveyController.java
index 7bb9ad88..239daf52 100644
--- a/survey-server/src/main/java/com/xiaojusurvey/engine/controller/SurveyController.java
+++ b/survey-server/src/main/java/com/xiaojusurvey/engine/controller/SurveyController.java
@@ -16,6 +16,7 @@
import com.xiaojusurvey.engine.core.survey.param.SurveyMetaUpdateParam;
import com.xiaojusurvey.engine.core.survey.vo.SurveyInfoInVO;
import com.xiaojusurvey.engine.core.survey.vo.SurveyInfoOutVO;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -32,6 +33,7 @@
*/
@RequestMapping("/api/survey")
@RestController
+@Slf4j
public class SurveyController {
@Resource
private SurveyService surveyService;
@@ -126,4 +128,22 @@ public RpcResult deleteSurvey(@RequestBody @Validated(SurveyMetaUpdateParam.Dele
}
return RpcResultUtil.createFailedResult(RespErrorCode.DELETE_SURVEY_ERROR.getCode(), RespErrorCode.DELETE_SURVEY_ERROR.getMessage());
}
+
+ /**
+ * 发布问卷
+ *
+ * @param surveyId
+ * @return
+ */
+ @PostMapping("/publishSurvey")
+ public RpcResult publishSurvey(@RequestParam @NotBlank(message = "问卷ID不能为空") String surveyId) {
+ log.info("[publishSurvey] 发布问卷,surveyId={}", surveyId);
+ boolean flag = surveyService.publishSurvey(surveyId);
+ if (flag) {
+ return RpcResultUtil.createSuccessResult(null);
+ }
+ return RpcResultUtil.createFailedResult(RespErrorCode.PUBLISH_SURVEY_ERROR.getCode(), RespErrorCode.PUBLISH_SURVEY_ERROR.getMessage());
+ }
+
+
}
diff --git a/survey-server/src/test/java/com/xiaojusurvey/engine/controller/SurveyControllerTest.java b/survey-server/src/test/java/com/xiaojusurvey/engine/controller/SurveyControllerTest.java
index 5cb1aad7..9324914f 100644
--- a/survey-server/src/test/java/com/xiaojusurvey/engine/controller/SurveyControllerTest.java
+++ b/survey-server/src/test/java/com/xiaojusurvey/engine/controller/SurveyControllerTest.java
@@ -20,6 +20,7 @@
import org.mockito.Mockito;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.ui.ModelExtensionsKt;
import javax.servlet.http.HttpServletRequest;
@@ -90,4 +91,12 @@ public void getSurvey() {
Assert.assertEquals(new Integer(200), surveyResult2.getCode());
}
+
+ @Test
+ public void publishSurveyTest() {
+
+ Mockito.when(surveyService.publishSurvey(Mockito.any())).thenReturn(true);
+ surveyController.publishSurvey("11111");
+
+ }
}