|
@@ -0,0 +1,227 @@
|
|
|
+package com.gis.service.impl;
|
|
|
+
|
|
|
+import com.gis.common.constant.MsgCode;
|
|
|
+import com.gis.common.exception.BaseRuntimeException;
|
|
|
+import com.gis.common.util.Result;
|
|
|
+import com.gis.domain.dto.PageDateDto;
|
|
|
+import com.gis.domain.dto.QuestionGroupDto;
|
|
|
+import com.gis.domain.po.QuestionEntity;
|
|
|
+import com.gis.domain.po.QuestionGroupEntity;
|
|
|
+import com.gis.mapper.IBaseMapper;
|
|
|
+import com.gis.mapper.QuestionGroupMapper;
|
|
|
+import com.gis.service.FileService;
|
|
|
+import com.gis.service.QuestionGroupService;
|
|
|
+import com.gis.service.QuestionService;
|
|
|
+import com.github.pagehelper.PageInfo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import tk.mybatis.mapper.entity.Condition;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by owen on 2020/3/11 0011 16:16
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class QuestionGroupServiceImpl extends IBaseServiceImpl<QuestionGroupEntity, Long> implements QuestionGroupService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private QuestionGroupMapper entityMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ HttpServletRequest request;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ FileService fileService;
|
|
|
+
|
|
|
+// @Autowired
|
|
|
+// AuditLogService auditLogService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ QuestionService questionService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IBaseMapper<QuestionGroupEntity, Long> getBaseMapper() {
|
|
|
+ return this.entityMapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<QuestionGroupEntity> search(PageDateDto param, Integer display) {
|
|
|
+ startPage(param);
|
|
|
+ Condition condition = new Condition(QuestionGroupEntity.class);
|
|
|
+ String searchKey = param.getSearchKey();
|
|
|
+ if (StringUtils.isNotBlank(searchKey)) {
|
|
|
+ searchKey = StringUtils.trim(searchKey);
|
|
|
+ condition.and().orLike("name", "%" + searchKey + "%");
|
|
|
+// .orLike("userName", "%" + searchKey + "%");
|
|
|
+ }
|
|
|
+ String startTime = param.getStartTime();
|
|
|
+ String endTime = param.getEndTime();
|
|
|
+ if (StringUtils.isNotBlank(startTime) && StringUtils.isNotBlank(endTime) ) {
|
|
|
+ condition.and().andBetween("createTime", startTime, endTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (display != null) {
|
|
|
+ condition.and().andEqualTo("display", display);
|
|
|
+ }
|
|
|
+ condition.orderBy("createTime").desc();
|
|
|
+
|
|
|
+ PageInfo<QuestionGroupEntity> pageInfo = this.findAll(condition, param.getPageNum(), param.getPageSize());
|
|
|
+// List<QuestionGroupEntity> list = pageInfo.getList();
|
|
|
+//
|
|
|
+// List<QuestionGroupEntity> result = new ArrayList<>();
|
|
|
+//
|
|
|
+// for (QuestionGroupEntity q : list) {
|
|
|
+// Integer count = getQuesitongCount(q.getId());
|
|
|
+// q.setQuestionCount(count);
|
|
|
+// result.add(q);
|
|
|
+// }
|
|
|
+//
|
|
|
+// pageInfo.setList(result);
|
|
|
+
|
|
|
+ return Result.success(pageInfo);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+// private Integer getQuesitongCount(Long id){
|
|
|
+// List<QuestionEntityEntity> answerEntityList = questionEntityService.findByQuestionGroupId(id);
|
|
|
+// return answerEntityList.size();
|
|
|
+// }
|
|
|
+
|
|
|
+// @Override
|
|
|
+// public Result apply(Long id) {
|
|
|
+// // 1:审核中
|
|
|
+// updateStatus(id, 1);
|
|
|
+// return Result.success();
|
|
|
+// }
|
|
|
+
|
|
|
+// @Override
|
|
|
+// public Result audit(AuditDto param) {
|
|
|
+// // 2:审核不通过, 3:审核通过
|
|
|
+// Integer status = param.getStatus();
|
|
|
+// if (status == 0) {
|
|
|
+// // 审核不通过
|
|
|
+// status = 2;
|
|
|
+// } else if (status == 1){
|
|
|
+// // 审核通过
|
|
|
+// status = 3;
|
|
|
+// } else {
|
|
|
+// throw new BaseRuntimeException(MsgCode.e3004, "审核状态非法");
|
|
|
+// }
|
|
|
+// Long id = param.getId();
|
|
|
+// updateStatus(id, status);
|
|
|
+// // 记录审核日志
|
|
|
+// auditLogService.saveAuditLog(TypeCode.MODULE_QUESTION_GROUP, id, param.getStatus(), param.getReason());
|
|
|
+// return Result.success();
|
|
|
+// }
|
|
|
+
|
|
|
+// @Override
|
|
|
+// public Result auditDetail(Long id) {
|
|
|
+// List<AuditLogEntity> list = auditLogService.findByModuleId(id, TypeCode.MODULE_QUESTION_GROUP);
|
|
|
+// return Result.success(list);
|
|
|
+// }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result updateDisplay(Long id) {
|
|
|
+ QuestionGroupEntity entity = this.findById(id);
|
|
|
+ if (entity == null) {
|
|
|
+ log.error("对象id不存在 : {}", id);
|
|
|
+ return Result.failure("对象id不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 不显示全部
|
|
|
+ entityMapper.disableAll();
|
|
|
+ // 显示当前id
|
|
|
+ entityMapper.enabledById(id);
|
|
|
+
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// private void updateStatus(Long id, Integer status){
|
|
|
+// QuestionGroupEntity entity = this.findById(id);
|
|
|
+// if (entity == null) {
|
|
|
+// throw new BaseRuntimeException(MsgCode.e3001, "对象不存在");
|
|
|
+// }
|
|
|
+// entity.setStatus(status);
|
|
|
+// entity.setUpdateTime(LocalDateTime.now());
|
|
|
+// this.update(entity);
|
|
|
+// }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result saveEntity(QuestionGroupDto param) {
|
|
|
+ Long id = param.getId();
|
|
|
+ QuestionGroupEntity entity = null;
|
|
|
+ if (id == null) {
|
|
|
+ entity = new QuestionGroupEntity();
|
|
|
+ entity.setDisplay(1);
|
|
|
+ entity.setName(param.getName());
|
|
|
+ entity.setUserName(getTokenUserName(request));
|
|
|
+ this.save(entity);
|
|
|
+ } else {
|
|
|
+ entity = this.findById(id);
|
|
|
+ if (entity == null) {
|
|
|
+ return Result.failure("对象不存在: " + id);
|
|
|
+ }
|
|
|
+ entity.setName(param.getName());
|
|
|
+ entity.setUpdateTime(LocalDateTime.now());
|
|
|
+ this.update(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ Long groupId = entity.getId();
|
|
|
+ // 将绑定的问题组id的问题答案设置为null
|
|
|
+// questionEntityService.removeByQuestionGroupId(entity.getId());
|
|
|
+ questionService.disableByQuestionGroupId(groupId);
|
|
|
+ // 绑定答案
|
|
|
+ String questionIds = param.getQuestionIds();
|
|
|
+ if (StringUtils.isNotBlank(questionIds)) {
|
|
|
+ questionService.updateQuestionGroupId(groupId, questionIds);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return Result.success(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result remove(Long id) {
|
|
|
+ QuestionGroupEntity entity = this.findById(id);
|
|
|
+ if (entity == null) {
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+ // db数据软删除, 物理数据真删除
|
|
|
+ entity.setIsDelete(1);
|
|
|
+ entity.setUpdateTime(LocalDateTime.now());
|
|
|
+ this.update(entity);
|
|
|
+ // 相应的答案删除
|
|
|
+ questionService.removeByQuestionGroupId(id);
|
|
|
+
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<QuestionGroupEntity> detail(Long id) {
|
|
|
+ QuestionGroupEntity entity = this.findById(id);
|
|
|
+ if (entity == null) {
|
|
|
+ return Result.failure("对象不存在");
|
|
|
+ }
|
|
|
+ List<QuestionEntity> list = questionService.findByQuestionGroupId(id);
|
|
|
+ HashMap<Object, Object> result = new HashMap<>();
|
|
|
+ result.put("entity", entity);
|
|
|
+ result.put("answer", list);
|
|
|
+ return Result.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|