|
|
@@ -0,0 +1,133 @@
|
|
|
+package com.zhongshu.card.server.core.dao.payment.impl;
|
|
|
+
|
|
|
+import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
|
|
|
+import com.zhongshu.card.client.model.payment.ExpenseFlowCount;
|
|
|
+import com.zhongshu.card.client.model.payment.ExpenseFlowSearch;
|
|
|
+import com.zhongshu.card.client.model.school.BookInfoSearch;
|
|
|
+import com.zhongshu.card.server.core.dao.BaseImpl;
|
|
|
+import com.zhongshu.card.server.core.dao.payment.extend.ExpenseFlowDaoExtend;
|
|
|
+import com.zhongshu.card.server.core.dao.school.extend.BookInfoDaoExtend;
|
|
|
+import com.zhongshu.card.server.core.domain.org.Department;
|
|
|
+import com.zhongshu.card.server.core.domain.payment.ExpenseFlow;
|
|
|
+import com.zhongshu.card.server.core.domain.school.BookInfo;
|
|
|
+import com.zhongshu.card.server.core.util.CommonUtil;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
+import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
|
|
+import org.springframework.data.mongodb.core.aggregation.AggregationOperation;
|
|
|
+import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
+import org.springframework.data.mongodb.core.query.Query;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author TRX
|
|
|
+ * @CreateDate: 2023/4/12
|
|
|
+ * @Version: 1.0
|
|
|
+ */
|
|
|
+public class ExpenseFlowDaoImpl extends BaseImpl implements ExpenseFlowDaoExtend {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MongoTemplate mongoTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DBHelper dbHelper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<ExpenseFlow> page(Pageable pageable, ExpenseFlowSearch param) {
|
|
|
+ Criteria criteria = buildCriteria(param);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(param.getUserId())) {
|
|
|
+ criteria.and("userId").is(param.getUserId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(param.getYear())) {
|
|
|
+ criteria.and("year").is(param.getYear());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(param.getMonth())) {
|
|
|
+ criteria.and("month").is(param.getMonth());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!CommonUtil.longIsEmpty(param.getStartTime()) && !CommonUtil.longIsEmpty(param.getEndTime())) {
|
|
|
+ criteria.and("createTime").gte(param.getStartTime()).and("createTime").lte(param.getEndTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 模糊搜索
|
|
|
+ List<Criteria> criterias = new ArrayList<>();
|
|
|
+ if (StringUtils.isNotEmpty(param.getOrderNo())) {
|
|
|
+ Pattern pattern = Pattern.compile("^.*" + param.getOrderNo() + ".*$");
|
|
|
+ criterias.add(Criteria.where("orderNo").is(pattern));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(param.getPaymentNo())) {
|
|
|
+ Pattern pattern = Pattern.compile("^.*" + param.getPaymentNo() + ".*$");
|
|
|
+ criterias.add(Criteria.where("paymentNo").is(pattern));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(criterias)) {
|
|
|
+ criteria.andOperator(criterias.toArray(new Criteria[]{}));
|
|
|
+ }
|
|
|
+
|
|
|
+ Sort sort = buildSort(param);
|
|
|
+ Query query = Query.query(criteria);
|
|
|
+ query.with(sort);
|
|
|
+ return dbHelper.pages(query, pageable, ExpenseFlow.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 统计
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ExpenseFlowCount countPayment(ExpenseFlowSearch param) {
|
|
|
+ ExpenseFlowCount expenseFlowCount = new ExpenseFlowCount();
|
|
|
+ Criteria criteria = buildCriteria(param);
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(param.getUserId())) {
|
|
|
+ criteria.and("userId").is(param.getUserId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(param.getYear())) {
|
|
|
+ criteria.and("year").is(param.getYear());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(param.getMonth())) {
|
|
|
+ criteria.and("month").is(param.getMonth());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!CommonUtil.longIsEmpty(param.getStartTime()) && !CommonUtil.longIsEmpty(param.getEndTime())) {
|
|
|
+ criteria.and("createTime").gte(param.getStartTime()).and("createTime").lte(param.getEndTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<AggregationOperation> operations = new ArrayList<>(2);
|
|
|
+ AggregationOperation match = Aggregation.match(criteria);
|
|
|
+ operations.add(match);
|
|
|
+
|
|
|
+ AggregationOperation group = Aggregation.group("$userId").sum("$payAmount").as("count");
|
|
|
+ operations.add(group);
|
|
|
+
|
|
|
+ BigDecimal number = BigDecimal.ZERO;
|
|
|
+ Aggregation groupAggregation = Aggregation.newAggregation(operations);
|
|
|
+ List<Map> countObjs = mongoTemplate.aggregate(groupAggregation, ExpenseFlow.class, Map.class).getMappedResults();
|
|
|
+ if (countObjs.size() > 0) {
|
|
|
+ Map map = countObjs.get(0);
|
|
|
+ Object obj = map.get("count");
|
|
|
+ number = CommonUtil.getBigDecimalByObj(obj);
|
|
|
+ }
|
|
|
+ expenseFlowCount.setPayAmount(number);
|
|
|
+ return expenseFlowCount;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|