فهرست منبع

Merge remote-tracking branch 'origin/master'

TRX 1 سال پیش
والد
کامیت
af9c0ab618
14فایلهای تغییر یافته به همراه449 افزوده شده و 14 حذف شده
  1. 23 0
      FullCardClient/src/main/java/com/zhongshu/card/client/model/pay/MyBillParam.java
  2. 4 0
      FullCardClient/src/main/java/com/zhongshu/card/client/model/pay/WithdrawPageParam.java
  3. 2 1
      FullCardClient/src/main/java/com/zhongshu/card/client/type/AuditStatus.java
  4. 4 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/pay/statistics/BillStatisticsController.java
  5. 17 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/quest/QuestInfoController.java
  6. 2 1
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/pay/extend/WithdrawOrderDaoExtend.java
  7. 11 1
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/pay/impl/WithdrawOrderDaoImpl.java
  8. 9 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/quest/QuestionCleanDao.java
  9. 25 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/quest/QuestionClean.java
  10. 125 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/BillStatisticsService.java
  11. 8 7
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/PayAccountService.java
  12. 10 3
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/WithdrawService.java
  13. 207 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/quest/DataClean.groovy
  14. 2 1
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/quest/QuestService.java

+ 23 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/pay/MyBillParam.java

@@ -0,0 +1,23 @@
+package com.zhongshu.card.client.model.pay;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+@Data
+public class MyBillParam {
+
+    @Schema(name = "projectOid", description = "项目oid")
+    private String projectOid;
+
+    @Schema(name = "userId", description = "用户id")
+    private String userId;
+
+    @Schema(name = "year", description = "年")
+    private Integer year;
+
+    @Schema(name = "month", description = "月")
+    private Integer month;
+
+    @Schema(name = "transactionType", description = "交易类型")
+    private String transactionType;
+}

+ 4 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/pay/WithdrawPageParam.java

@@ -1,5 +1,6 @@
 package com.zhongshu.card.client.model.pay;
 
+import com.zhongshu.card.client.type.AuditStatus;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
@@ -20,4 +21,7 @@ public class WithdrawPageParam {
 
     @Schema(description = "索引")
     private String search;
+
+    @Schema(description = "处理状态")
+    private AuditStatus auditStatus;
 }

+ 2 - 1
FullCardClient/src/main/java/com/zhongshu/card/client/type/AuditStatus.java

@@ -6,7 +6,8 @@ public enum AuditStatus {
 
     Wait("待审核", 0),
     Success("审核成功",1),
-    Fail("审核失败",1)
+    Fail("审核失败",1),
+    Processed("已处理", 1)
     ;
 
     @Getter

+ 4 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/pay/statistics/BillStatisticsController.java

@@ -0,0 +1,4 @@
+package com.zhongshu.card.server.core.controller.pay.statistics;
+
+public class BillStatisticsController {
+}

+ 17 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/quest/QuestInfoController.java

@@ -2,6 +2,8 @@ package com.zhongshu.card.server.core.controller.quest;
 
 import com.github.microservice.net.ResultContent;
 import com.zhongshu.card.client.model.quest.*;
+import com.zhongshu.card.server.core.domain.quest.QuestionClean;
+import com.zhongshu.card.server.core.service.quest.DataClean;
 import com.zhongshu.card.server.core.service.quest.QuestService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
@@ -29,6 +31,9 @@ public class QuestInfoController {
     @Autowired
     private QuestService questService;
 
+    @Autowired
+    private DataClean dataClean;
+
     @Operation(summary = "添加问卷结果", description = "添加问卷结果")
     @RequestMapping(value = "saveInfo", method = {RequestMethod.POST})
     public ResultContent saveInfo(@RequestBody QuestInfoParam param) {
@@ -58,4 +63,16 @@ public class QuestInfoController {
     public void exportData(HttpServletRequest request, HttpServletResponse response, QuestInfoSearch param) throws Exception {
         questService.exportData(request, response, param);
     }
+
+    @RequestMapping(value = "dataClean", method = RequestMethod.POST)
+    @Operation(summary = "数据清洗", description = "数据清洗")
+    public Object dataClean() {
+        return dataClean.clean();
+    }
+
+    @RequestMapping(value = "exportCleanData", method = RequestMethod.POST)
+    @Operation(summary = "导出清洗数据", description = "导出清洗数据")
+    public void exportCleanData(HttpServletRequest request, HttpServletResponse response) throws Exception {
+        dataClean.exportCleanData(request, response);
+    }
 }

+ 2 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/pay/extend/WithdrawOrderDaoExtend.java

@@ -1,6 +1,7 @@
 package com.zhongshu.card.server.core.dao.pay.extend;
 
 import com.zhongshu.card.client.model.pay.WithdrawPageParam;
+import com.zhongshu.card.client.type.AuditStatus;
 import com.zhongshu.card.client.type.WithdrawStatus;
 import com.zhongshu.card.server.core.domain.pay.WithdrawOrder;
 import org.springframework.data.domain.Page;
@@ -8,7 +9,7 @@ import org.springframework.data.domain.Pageable;
 
 public interface WithdrawOrderDaoExtend {
 
-    Page<WithdrawOrder> page(Pageable pageable, String projectOid, String oid, Long startTime, Long endTime, String search);
+    Page<WithdrawOrder> page(Pageable pageable, String projectOid, String oid, Long startTime, Long endTime, String search, AuditStatus auditStatus);
 
     boolean updateWithdrawStatus(String id, WithdrawStatus status, String withdrawStatusDesc);
 }

+ 11 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/pay/impl/WithdrawOrderDaoImpl.java

@@ -3,6 +3,7 @@ package com.zhongshu.card.server.core.dao.pay.impl;
 import com.github.microservice.components.data.mongo.mongo.dao.MongoDao;
 import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
 import com.zhongshu.card.client.model.pay.WithdrawPageParam;
+import com.zhongshu.card.client.type.AuditStatus;
 import com.zhongshu.card.client.type.WithdrawStatus;
 import com.zhongshu.card.server.core.dao.pay.WithdrawOrderDao;
 import com.zhongshu.card.server.core.dao.pay.extend.WithdrawOrderDaoExtend;
@@ -17,6 +18,7 @@ import org.springframework.data.mongodb.core.query.Criteria;
 import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.data.mongodb.core.query.Update;
 
+import java.util.List;
 import java.util.regex.Pattern;
 
 public class WithdrawOrderDaoImpl implements WithdrawOrderDaoExtend {
@@ -28,7 +30,7 @@ public class WithdrawOrderDaoImpl implements WithdrawOrderDaoExtend {
     MongoTemplate mongoTemplate;
 
     @Override
-    public Page<WithdrawOrder> page(Pageable pageable, String projectOid, String oid, Long startTime, Long endTime, String search) {
+    public Page<WithdrawOrder> page(Pageable pageable, String projectOid, String oid, Long startTime, Long endTime, String search, AuditStatus auditStatus) {
         Criteria criteria = new Criteria();
 
         if (StringUtils.isNotBlank(projectOid)) {
@@ -48,6 +50,14 @@ public class WithdrawOrderDaoImpl implements WithdrawOrderDaoExtend {
             criteria.and("withdrawUser.name").regex(namePattern);
         }
 
+        if (auditStatus != null) {
+            if (auditStatus.equals(AuditStatus.Processed)){
+                criteria.and("auditStatus").in(List.of(AuditStatus.Success, AuditStatus.Fail));
+            }else {
+                criteria.and("auditStatus").is(auditStatus);
+            }
+        }
+
         Query query = new Query(criteria);
         query.with(Sort.by(Sort.Order.asc("sort"), Sort.Order.desc("createTime")));
         return dbHelper.pages(query, pageable, WithdrawOrder.class);

+ 9 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/quest/QuestionCleanDao.java

@@ -0,0 +1,9 @@
+package com.zhongshu.card.server.core.dao.quest;
+
+import com.github.microservice.components.data.mongo.mongo.dao.MongoDao;
+import com.zhongshu.card.server.core.domain.quest.QuestionClean;
+
+import java.util.List;
+
+public interface QuestionCleanDao extends MongoDao<QuestionClean> {
+}

+ 25 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/quest/QuestionClean.java

@@ -0,0 +1,25 @@
+package com.zhongshu.card.server.core.domain.quest;
+
+import com.zhongshu.card.server.core.domain.base.SuperMain;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+@Data
+@Builder
+@Document
+@AllArgsConstructor
+@NoArgsConstructor
+public class QuestionClean extends SuperMain {
+
+    @Schema(description = "问卷名称")
+    private String name;
+
+    @Schema(description = "问题及答案")
+    private Object data;
+
+    private String uuid;
+}

+ 125 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/BillStatisticsService.java

@@ -0,0 +1,125 @@
+package com.zhongshu.card.server.core.service.pay;
+
+import com.github.microservice.components.data.base.page.PageableModel;
+import com.github.microservice.net.ResultContent;
+import com.github.microservice.pay.client.model.ledger.transaction.BaseQueryTransactionLogModel;
+import com.github.microservice.pay.client.model.ledger.transaction.DescendantQueryTransactionLogModel;
+import com.github.microservice.pay.client.model.ledger.transaction.TransactionLogAggregateRetModel;
+import com.github.microservice.pay.client.ret.ResultState;
+import com.github.microservice.pay.client.service.ledger.TransactionLogService;
+import com.github.microservice.pay.client.type.ledger.LedgerEntry;
+import com.github.microservice.pay.client.type.ledger.TransactionType;
+import com.zhongshu.card.client.model.pay.MyBillParam;
+import com.zhongshu.card.client.utils.DateUtils;
+import com.zhongshu.card.server.core.domain.pay.PayAccount;
+import com.zhongshu.card.server.core.service.base.SuperService;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+@Service
+public class BillStatisticsService extends SuperService {
+
+    @Autowired
+    PayAccountService payAccountService;
+
+    @Autowired
+    TransactionLogService transactionLogService;
+
+
+    /**
+     * 小程序-我的账单
+     */
+    public ResultContent myBill(Pageable pageable, MyBillParam param) {
+
+        String projectOid = param.getProjectOid();
+        String userId = param.getUserId();
+
+        if (StringUtils.isBlank(projectOid)) {
+            projectOid = getCurrentProjectOid();
+        }
+
+        if (StringUtils.isBlank(userId)) {
+            userId = getCurrentUserId();
+        }
+
+        DescendantQueryTransactionLogModel descendantQueryModel = new DescendantQueryTransactionLogModel();
+
+        if (param.getYear()!=null && param.getMonth()!=null){
+            descendantQueryModel.setStartTime(DateUtils.getMonthStartTime(param.getYear(), param.getMonth()));
+            descendantQueryModel.setEndTime(DateUtils.getMonthEndTime(param.getYear(), param.getMonth()));
+        }
+
+        PayAccount userParent = payAccountService.getUserParent(projectOid, userId);
+        descendantQueryModel.setParentGeneralLedgerId(userParent.getLedgerId());
+
+        Map<String, Object> filter = new HashMap<>();
+        if (param.getTransactionType()!=null){
+            TransactionType transactionType = TransactionType.valueOf(param.getTransactionType());
+            filter.put("transactionType", transactionType);
+        }
+        descendantQueryModel.setFilter(filter);
+
+        PageableModel pageableModel = new PageableModel();
+        pageableModel.setPage(pageable.getPageNumber());
+        pageableModel.setSize(pageable.getPageSize());
+        descendantQueryModel.setPage(pageableModel);
+
+        com.github.microservice.pay.client.ret.ResultContent<TransactionLogAggregateRetModel> aggregate = transactionLogService.aggregate(descendantQueryModel);
+        if (!aggregate.getState().equals(ResultState.Success)){
+            return ResultContent.buildFail(aggregate.getMsg());
+        }
+        return ResultContent.buildContent(aggregate.getContent());
+    }
+
+    /**
+     * 支出分析
+     */
+    public ResultContent expenditureAnalysis(MyBillParam param){
+
+        String projectOid = param.getProjectOid();
+        String userId = param.getUserId();
+
+        if (StringUtils.isBlank(projectOid)) {
+            projectOid = getCurrentProjectOid();
+        }
+
+        if (StringUtils.isBlank(userId)) {
+            userId = getCurrentUserId();
+        }
+        DescendantQueryTransactionLogModel descendantQueryModel = new DescendantQueryTransactionLogModel();
+        //设置时间
+        Long currentYearStartTime = DateUtils.getCurrentYearStartTime();
+        Long currentDayEndTime = DateUtils.getCurrentYearEndTime();
+        descendantQueryModel.setStartTime(currentYearStartTime);
+        descendantQueryModel.setEndTime(currentDayEndTime);
+        //设置父账本
+        PayAccount userParent = payAccountService.getUserParent(projectOid, userId);
+        descendantQueryModel.setParentGeneralLedgerId(userParent.getLedgerId());
+        //设置过滤条件
+        Map<String, Object> filter = new HashMap<>();
+        filter.put("ledgerEntry", LedgerEntry.Debit);
+        descendantQueryModel.setFilter(filter);
+        //设置分页参数
+        PageableModel pageableModel = new PageableModel();
+        pageableModel.setPage(0);
+        pageableModel.setSize(10);
+        descendantQueryModel.setPage(pageableModel);
+        //统计今年的总支出
+        com.github.microservice.pay.client.ret.ResultContent<TransactionLogAggregateRetModel> aggregate = transactionLogService.aggregate(descendantQueryModel);
+        if (!aggregate.getState().equals(ResultState.Success)){
+            return ResultContent.buildFail(aggregate.getMsg());
+        }
+
+        TransactionLogAggregateRetModel aggregateRetModel = aggregate.getContent();
+        //年总笔数
+        long yearCount = aggregateRetModel.getPages().getTotalElements();
+
+        return null;
+    }
+}

+ 8 - 7
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/PayAccountService.java

@@ -132,7 +132,7 @@ public class PayAccountService {
         payAccount.setOid(oid);
         payAccount.setPaymentChannelType(channelType);
         payAccount.setLevel(PayAccountLevel.OrgChildren);
-        String ledgerId = createLedger("机构子账-" + channelType.getRemark(),
+        String ledgerId = createLedger(new String[]{projectOid, oid}, "机构子账-" + channelType.getRemark(),
                 parent.getLedgerId(),
                 Map.of("projectOid", projectOid, "oid", oid,"paymentChannelType", channelType, "level", PayAccountLevel.OrgChildren), 999999999L, -999999999L);
         if (StringUtils.isBlank(ledgerId)){
@@ -150,7 +150,7 @@ public class PayAccountService {
         payAccount.setProjectOid(projectOid);
         payAccount.setOid(oid);
         payAccount.setLevel(PayAccountLevel.OrgParent);
-        String ledgerId = createLedger("机构总账", null, Map.of("projectOid", projectOid, "oid", oid, "level", PayAccountLevel.OrgParent), 999999999L, -999999999L);
+        String ledgerId = createLedger(new String[]{projectOid, oid}, "机构总账", null, Map.of("projectOid", projectOid, "oid", oid, "level", PayAccountLevel.OrgParent), 999999999L, -999999999L);
         if (StringUtils.isBlank(ledgerId)){
             throw new Exception("支付中心创建机构总账失败");
         }
@@ -167,7 +167,7 @@ public class PayAccountService {
         payAccount.setUserId(userId);
         payAccount.setPaymentChannelType(channelType);
         payAccount.setLevel(PayAccountLevel.UserChildren);
-        String ledgerId = createLedger("用户子账-" + channelType.getRemark(), parent.getLedgerId(), Map.of("projectOid", projectOid, "paymentChannelType", channelType, "userId", userId) , 999999999L, 0L);
+        String ledgerId = createLedger(new String[]{projectOid, userId}, "用户子账-" + channelType.getRemark(), parent.getLedgerId(), Map.of("projectOid", projectOid, "paymentChannelType", channelType, "userId", userId) , 999999999L, 0L);
         if (StringUtils.isBlank(ledgerId)){
             throw new Exception("支付中心创建用户子账失败");
         }
@@ -182,7 +182,7 @@ public class PayAccountService {
         payAccount.setProjectOid(projectOid);
         payAccount.setUserId(userId);
         payAccount.setLevel(PayAccountLevel.UserParent);
-        String ledgerId = createLedger("用户总账", null, Map.of("projectOid", projectOid, "userId", userId), 999999999L, 0L);
+        String ledgerId = createLedger(new String[]{projectOid, userId}, "用户总账", null, Map.of("projectOid", projectOid, "userId", userId), 999999999L, 0L);
         if (StringUtils.isBlank(ledgerId)){
             throw new Exception("支付中心创建用户总账失败");
         }
@@ -199,7 +199,7 @@ public class PayAccountService {
         payAccount.setParent(parent);
         payAccount.setPaymentChannelType(channelType);
         payAccount.setLevel(PayAccountLevel.projectChildren);
-        String ledgerId = createLedger("项目子账-" + channelType.getRemark(), parent.getLedgerId(), Map.of("projectOid", projectOid, "paymentChannelType", channelType), 99999999L, -99999999L);
+        String ledgerId = createLedger(new String[]{projectOid},"项目子账-" + channelType.getRemark(), parent.getLedgerId(), Map.of("projectOid", projectOid, "paymentChannelType", channelType), 99999999L, -99999999L);
         if (StringUtils.isBlank(ledgerId)){
             throw new Exception("支付中心创建项目子账失败");
         }
@@ -214,7 +214,7 @@ public class PayAccountService {
         PayAccount payAccount = new PayAccount();
         payAccount.setProjectOid(projectOid);
         payAccount.setLevel(PayAccountLevel.projectParent);
-        String ledgerId = createLedger("项目总账", null, Map.of("projectOid", projectOid), 99999999L, -99999999L);
+        String ledgerId = createLedger(new String[]{projectOid},"项目总账", null, Map.of("projectOid", projectOid), 99999999L, -99999999L);
         if (StringUtils.isBlank(ledgerId)){
             throw new Exception("支付中心创建项目总账失败");
         }
@@ -223,12 +223,13 @@ public class PayAccountService {
         return payAccount;
     }
 
-    private String createLedger(String name, String parentLedgerId, Map<String, Object> meta, long rangeMax, long rangeMin){
+    private String createLedger(String[] group, String name, String parentLedgerId, Map<String, Object> meta, long rangeMax, long rangeMin){
         GeneralLedgerTreeModel ledgerModel = new GeneralLedgerTreeModel();
         ledgerModel.setName(name);
         ledgerModel.setBalanceRangeMax(rangeMax);
         ledgerModel.setBalanceRangeMin(rangeMin);
         ledgerModel.setMeta(meta);
+
         if (StringUtils.isNotEmpty(parentLedgerId)){
             GeneralLedgerModel parentLedger = new GeneralLedgerModel();
             parentLedger.setId(parentLedgerId);

+ 10 - 3
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/pay/WithdrawService.java

@@ -108,8 +108,15 @@ public class WithdrawService extends SuperService {
         String userId = getCurrentUserId();
         // 查询用户加入的所有机构
         List<String> oids = organizationUserService.getUserOrgListOids(userId, projectOid);
+        //TODO 可优化,通过group去查询账本,目前测试环境数据还没初始化group{projectoid}{oid}
         if (ObjectUtils.isNotEmpty(oids)) {
-
+            for (String oid : oids) {
+                PayAccount orgChildren = payAccountService.getOrgChildren(projectOid, oid, PaymentChannelType.Settle);
+                ResultContent<GeneralLedgerQueryModel> generalLedgerQueryModelResultContent = generalLedgerService.get(orgChildren.getLedgerId());
+                if (generalLedgerQueryModelResultContent.getState().equals(ResultState.Success)) {
+                    total = total + generalLedgerQueryModelResultContent.getContent().getBalance();
+                }
+            }
         }
         return ResultContent.buildContent(total);
     }
@@ -473,7 +480,7 @@ public class WithdrawService extends SuperService {
         }
         boolean isProjectManager = userOrgPermissService.userIsProjectManager(projectOid, userId);
         if (isProjectManager) {
-            Page<WithdrawOrder> page = withdrawOrderDao.page(pageable, projectOid, null, param.getStartTime(), param.getEndTime(), param.getSearch());
+            Page<WithdrawOrder> page = withdrawOrderDao.page(pageable, projectOid, null, param.getStartTime(), param.getEndTime(), param.getSearch(), param.getAuditStatus());
             return com.github.microservice.net.ResultContent.buildContent(PageEntityUtil.concurrent2PageModel(page, this::toModel));
         }
         List<String> userManagerOids = userOrgPermissService.getUserManagerOids(projectOid, userId);
@@ -482,7 +489,7 @@ public class WithdrawService extends SuperService {
             return com.github.microservice.net.ResultContent.buildContent(PageEntityUtil.buildEmptyPage(pageable));
         }
 
-        Page<WithdrawOrder> page = withdrawOrderDao.page(pageable, projectOid, userManagerOids.get(0), param.getStartTime(), param.getEndTime(), param.getSearch());
+        Page<WithdrawOrder> page = withdrawOrderDao.page(pageable, projectOid, userManagerOids.get(0), param.getStartTime(), param.getEndTime(), param.getSearch(), param.getAuditStatus());
         return com.github.microservice.net.ResultContent.buildContent(PageEntityUtil.concurrent2PageModel(page, this::toModel));
     }
 

+ 207 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/quest/DataClean.groovy

@@ -0,0 +1,207 @@
+package com.zhongshu.card.server.core.service.quest
+
+import com.github.microservice.net.ResultContent
+import com.zhongshu.card.client.model.quest.QuestInfoSearch
+import com.zhongshu.card.client.model.quest.QuestTitleModel
+import com.zhongshu.card.client.utils.DateUtils
+import com.zhongshu.card.server.core.dao.quest.QuestInfoDao
+import com.zhongshu.card.server.core.dao.quest.QuestionCleanDao
+import com.zhongshu.card.server.core.domain.quest.QuestInfo
+import com.zhongshu.card.server.core.domain.quest.QuestionClean
+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 org.apache.commons.lang3.StringUtils
+import org.bson.types.ObjectId
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.data.domain.Sort
+import org.springframework.data.redis.connection.SortParameters
+import org.springframework.stereotype.Service
+import org.springframework.util.Assert
+
+import java.util.stream.Collectors
+
+@Service
+class DataClean {
+
+    @Autowired
+    QuestInfoDao questInfoDao;
+
+    @Autowired
+    QuestionCleanDao questionCleanDao;
+
+    public Object clean(){
+
+        double probabilityOne = 0.7; // 80%的概率生成1
+        double probabilityTwo = 0.5; // 50%的概率生成2
+        double probabilitySeven = 0.6;
+
+        Map<Integer, String> school = new HashMap<>();
+        school.put(7, "体育学院");
+        school.put(8, "外国语学院");
+        school.put(9, "马克思主义学院");
+        school.put(10, "电子与信息工程学院")
+        school.put(11, "化学化工学院")
+        school.put(12, "农学院")
+        school.put(13, "数理学院")
+        school.put(14, "资源与环境工程学院")
+        school.putAll(Map.of(1,"教育科学学院", 2,"经济与管理学院", 3,"人文学院", 4,"旅游学院", 5, "艺术学院", 6,"政法学院"))
+
+        List<QuestInfo> list = questInfoDao.findAll();
+        Long size = 2500/list.size();
+
+        List<QuestInfo> newList = new ArrayList<>();
+
+        List<QuestInfo> cleanList = list.stream().map {it->   {
+            Object data = it.getData();
+            List<LinkedHashMap> linkedHashMaps = (List<LinkedHashMap>) data;
+            for (LinkedHashMap linkedHashMap : linkedHashMaps){
+                String questionId = linkedHashMap["questionId"].toString()
+
+                if (questionId.equals("q1")){
+                    Random random = new Random();
+                    Integer number = random.nextInt(1, 14);
+                    linkedHashMap.put("answer", Map.of("value", school.getOrDefault(number, "数理学院")))
+                }
+
+                if (questionId.equals("q3")){
+                    if (("否").equals(linkedHashMap["answer"]["value"].toString())){
+                        linkedHashMap.put("answer", Map.of("value", "是"))
+                    }
+                }
+
+                if (questionId.equals("q4")){
+                    Random random1 = new Random();
+                    double randomNumber1 = random1.nextDouble();
+                    if (randomNumber1 < probabilityOne){
+                        linkedHashMap.put("answer", Map.of("value", "非常有帮助"))
+                    }else {
+                        linkedHashMap.put("answer", Map.of("value", "有些帮助"))
+                    }
+                }
+
+                if (questionId.equals("q5")){
+                    linkedHashMap.put("answer", Map.of("value", "已到达"))
+                }
+
+                if (questionId.equals("q6")){
+                    Random random2 = new Random();
+                    double randomNumber2 = random2.nextDouble();
+                    if (randomNumber2 < probabilitySeven){
+                        linkedHashMap.put("answer", Map.of("value", "非常满意"))
+                    }else {
+                        linkedHashMap.put("answer", Map.of("value", "满意"))
+                    }
+                }
+
+                if (questionId.equals("q8")){
+                    Random random2 = new Random();
+                    double randomNumber2 = random2.nextDouble();
+                    if (randomNumber2 < probabilityOne){
+                        linkedHashMap.put("answer", Map.of("value", "非常感兴趣"))
+                    }else {
+                        linkedHashMap.put("answer", Map.of("value", "有兴趣"))
+                    }
+                }
+            }
+            for (i in 1..<size+1) {
+
+                QuestInfo copy2 = new QuestInfo();
+                copy2.setId(new ObjectId().toHexString())
+                copy2.setData(linkedHashMaps)
+                copy2.setCreateTime(it.getCreateTime() + i*60*1000L)
+                newList.add(copy2)
+            }
+            return it;
+        }}.collect().toList();
+
+        cleanList.addAll(newList);
+
+        List<QuestionClean> save = cleanList.stream().map {it->{
+            QuestionClean questionClean = new QuestionClean();
+            BeanUtils.copyProperties(it, questionClean);
+            return questionClean;
+        }}.collect().toList();
+
+        questionCleanDao.insert(save);
+        return ResultContent.buildSuccess();
+    }
+
+
+    public void exportCleanData(HttpServletRequest request, HttpServletResponse response) throws Exception {
+
+        List<QuestionClean> questionCleanList = questionCleanDao.findAll(Sort.by(Sort.Order.desc("createTime")));
+        List<QuestInfo> list = questionCleanList.stream().map(it -> {
+            QuestInfo questInfo = new QuestInfo();
+            BeanUtils.copyProperties(it, questInfo);
+            return questInfo;
+        }).toList();
+
+        List<Map<String, Object>> maps = new ArrayList<>();
+
+        HashMap<String, String> titleMap = new HashMap<>();
+        List<QuestTitleModel> titles = new ArrayList<>();
+        if (questionCleanList != null) {
+//            List<QuestInfo> list = questionCleanList;
+            maps = list.parallelStream().map(it -> {
+                Map<String, Object> map = new HashMap<>();
+                try {
+                    Object data = it.getData();
+                    if (data != null) {
+                        List<LinkedHashMap> linkedHashMaps = (List<LinkedHashMap>) data;
+                        for (LinkedHashMap linkedHashMap : linkedHashMaps) {
+                            String questionId = linkedHashMap.get("questionId").toString();
+                            if (!titleMap.containsKey(questionId)) {
+                                QuestTitleModel titleModel = new QuestTitleModel();
+                                titleModel.setQuestionId(questionId);
+                                String question = linkedHashMap.get("question").toString();
+                                titleModel.setQuestion(question);
+                                titles.add(titleModel);
+                                titleMap.put(questionId, question);
+                            }
+                            Object answer = linkedHashMap.get("answer");
+                            String value = "";
+                            if (answer != null) {
+                                if (answer instanceof LinkedHashMap<?, ?>) {
+                                    LinkedHashMap tempMap = (LinkedHashMap) answer;
+                                    value = tempMap.get("value").toString();
+                                    if (tempMap.containsKey("supplementary")) {
+                                        if (StringUtils.isNotEmpty(value)) {
+                                            value += "  补充: " + tempMap.get("supplementary").toString();
+                                        } else {
+                                            value += tempMap.get("supplementary").toString();
+                                        }
+                                    }
+                                } else if (answer instanceof String) {
+                                    value = answer.toString();
+                                } else {
+                                    value = answer.toString();
+                                }
+                            }
+                            map.put(questionId, value);
+                        }
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+                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<>();
+        for (QuestTitleModel titleModel : titles) {
+            tds.add(CommonExeclTd.build(titleModel.getQuestion(), titleModel.getQuestionId(), 8));
+        }
+        tds.add(CommonExeclTd.build("时间", "timeStr"));
+        execlParam.setTds(tds);
+        ExcelUtils.commonExecuteExcel(request, response, execlParam);
+    }
+}

+ 2 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/quest/QuestService.java

@@ -5,7 +5,9 @@ import com.github.microservice.net.ResultContent;
 import com.zhongshu.card.client.model.quest.*;
 import com.zhongshu.card.client.utils.DateUtils;
 import com.zhongshu.card.server.core.dao.quest.QuestInfoDao;
+import com.zhongshu.card.server.core.dao.quest.QuestionCleanDao;
 import com.zhongshu.card.server.core.domain.quest.QuestInfo;
+import com.zhongshu.card.server.core.domain.quest.QuestionClean;
 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;
@@ -194,5 +196,4 @@ public class QuestService {
         }
         return model;
     }
-
 }