|
|
@@ -0,0 +1,134 @@
|
|
|
+package com.zhongshu.card.server.core.service.quest;
|
|
|
+
|
|
|
+import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
|
+import com.github.microservice.core.util.bean.BeanUtil;
|
|
|
+import com.github.microservice.net.ResultContent;
|
|
|
+import com.zhongshu.card.client.model.quest.QuestInfoModel;
|
|
|
+import com.zhongshu.card.client.model.quest.QuestInfoParam;
|
|
|
+import com.zhongshu.card.client.model.quest.QuestInfoSearch;
|
|
|
+import com.zhongshu.card.client.model.quest.QuestInfoUpdateParam;
|
|
|
+import com.zhongshu.card.client.utils.DateUtils;
|
|
|
+import com.zhongshu.card.server.core.dao.quest.QuestInfoDao;
|
|
|
+import com.zhongshu.card.server.core.domain.quest.QuestInfo;
|
|
|
+import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
+import com.zhongshu.card.server.core.util.ExcelUtils;
|
|
|
+import com.zhongshu.card.server.core.util.excel.CommonExeclParam;
|
|
|
+import com.zhongshu.card.server.core.util.excel.CommonExeclTd;
|
|
|
+import jakarta.servlet.http.HttpServletRequest;
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.Assert;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author TRX
|
|
|
+ * @date 2024/11/29
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class QuestService {
|
|
|
+
|
|
|
+ @Value("${quest.psd}")
|
|
|
+ public String psd = "";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private QuestInfoDao questInfoDao;
|
|
|
+
|
|
|
+ public ResultContent saveInfo(QuestInfoParam param) {
|
|
|
+ QuestInfo entity = new QuestInfo();
|
|
|
+ BeanUtils.copyProperties(param, entity);
|
|
|
+ questInfoDao.save(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent updateInfo(QuestInfoUpdateParam param) {
|
|
|
+ QuestInfo entity = questInfoDao.findTopById(param.getId());
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail("数据不存在");
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(param.getPsd())) {
|
|
|
+ return ResultContent.buildFail("操作密码为空");
|
|
|
+ }
|
|
|
+ if (!param.getPsd().equals(psd)) {
|
|
|
+ return ResultContent.buildFail("密码错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ BeanUtils.copyProperties(param, entity);
|
|
|
+ questInfoDao.save(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent<Page<QuestInfoModel>> page(QuestInfoSearch param, Pageable pageable) {
|
|
|
+ if (StringUtils.isEmpty(param.getPsd())) {
|
|
|
+ return ResultContent.buildFail("操作密码为空");
|
|
|
+ }
|
|
|
+ if (!param.getPsd().equals(psd)) {
|
|
|
+ return ResultContent.buildFail("密码错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<QuestInfo> page = questInfoDao.page(pageable, param);
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toModel));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent deleteById(String id) {
|
|
|
+ QuestInfo entity = questInfoDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail("数据不存在");
|
|
|
+ }
|
|
|
+ questInfoDao.delete(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void exportData(HttpServletRequest request, HttpServletResponse response, QuestInfoSearch param) throws Exception {
|
|
|
+ Assert.hasText(param.getPsd(), "psd不能为空");
|
|
|
+ if (!param.getPsd().equals(psd)) {
|
|
|
+ throw new Exception("密码错误");
|
|
|
+ }
|
|
|
+ Pageable pageable = PageRequest.of(0, Integer.MAX_VALUE);
|
|
|
+ Page<QuestInfo> page = questInfoDao.page(pageable, param);
|
|
|
+ List<Map<String, Object>> maps = new ArrayList<>();
|
|
|
+ if (page.getContent() != null) {
|
|
|
+ List<QuestInfo> list = page.getContent();
|
|
|
+ maps = list.stream().map(it -> {
|
|
|
+ Map<String, Object> map = BeanUtil.bean2Map(it);
|
|
|
+
|
|
|
+ map.put("timeStr", DateUtils.paresTime(it.getCreateTime(), DateUtils.patternyyyyMis));
|
|
|
+ return map;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ CommonExeclParam execlParam = new CommonExeclParam();
|
|
|
+ execlParam.setTitle(String.format("问卷调查"));
|
|
|
+ execlParam.setStartRow(2);
|
|
|
+ execlParam.setDatas(maps);
|
|
|
+ List<CommonExeclTd> tds = new ArrayList<>();
|
|
|
+ tds.add(CommonExeclTd.build("1", "code"));
|
|
|
+ tds.add(CommonExeclTd.build("2", "cardStr"));
|
|
|
+ tds.add(CommonExeclTd.build("3", "useStr"));
|
|
|
+ tds.add(CommonExeclTd.build("4", "cancelStr"));
|
|
|
+ tds.add(CommonExeclTd.build("时间", "timeStr"));
|
|
|
+ execlParam.setTds(tds);
|
|
|
+ ExcelUtils.commonExecuteExcel(request, response, execlParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ private QuestInfoModel toModel(QuestInfo entity) {
|
|
|
+ QuestInfoModel model = new QuestInfoModel();
|
|
|
+ if (ObjectUtils.isNotEmpty(entity)) {
|
|
|
+ BeanUtils.copyProperties(entity, model);
|
|
|
+ }
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|