|
@@ -0,0 +1,142 @@
|
|
|
+package com.qunzhixinxi.hnqz.admin;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.qunzhixinxi.hnqz.admin.entity.WmScorePackage;
|
|
|
+import com.qunzhixinxi.hnqz.admin.entity.WmScorePackageSettleNote;
|
|
|
+import com.qunzhixinxi.hnqz.admin.mapper.WmScorePackageMapper;
|
|
|
+import com.qunzhixinxi.hnqz.admin.mapper.WmScorePackageSettleNoteMapper;
|
|
|
+import com.qunzhixinxi.hnqz.admin.recharge.entity.SysDeptInvoice;
|
|
|
+import com.qunzhixinxi.hnqz.admin.recharge.entity.SysDeptInvoiceRelation;
|
|
|
+import com.qunzhixinxi.hnqz.admin.recharge.entity.SysDeptRecharge;
|
|
|
+import com.qunzhixinxi.hnqz.admin.recharge.enums.InvoiceApprovalStatus;
|
|
|
+import com.qunzhixinxi.hnqz.admin.recharge.enums.InvoiceStatus;
|
|
|
+import com.qunzhixinxi.hnqz.admin.recharge.enums.InvoiceType;
|
|
|
+import com.qunzhixinxi.hnqz.admin.recharge.mapper.SysDeptInvoiceMapper;
|
|
|
+import com.qunzhixinxi.hnqz.admin.recharge.mapper.SysDeptInvoiceRelationMapper;
|
|
|
+import com.qunzhixinxi.hnqz.admin.recharge.mapper.SysDeptRechargeMapper;
|
|
|
+import com.qunzhixinxi.hnqz.admin.recharge.mapper.SysDeptRechargeRecordMapper;
|
|
|
+import org.junit.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.test.annotation.Rollback;
|
|
|
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author snows
|
|
|
+ * @date 2023/7/6 15:56
|
|
|
+ */
|
|
|
+@RunWith(SpringJUnit4ClassRunner.class)
|
|
|
+@SpringBootTest(classes = {HnqzAdminApplication.class, Test.class})
|
|
|
+public class SysDeptInvoiceServiceTest {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WmScorePackageMapper scorePackageMapper;
|
|
|
+ @Autowired
|
|
|
+ private WmScorePackageSettleNoteMapper scorePackageSettleNoteMapper;
|
|
|
+ @Autowired
|
|
|
+ private SysDeptInvoiceMapper deptInvoiceMapper;
|
|
|
+ @Autowired
|
|
|
+ private SysDeptInvoiceRelationMapper deptInvoiceRelationMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化已开票的数据
|
|
|
+ */
|
|
|
+// @Test
|
|
|
+// @Transactional(rollbackFor = Exception.class)
|
|
|
+// @Rollback(value = false)
|
|
|
+ public void initInvoicedData() {
|
|
|
+ List<Integer> deptList = null;
|
|
|
+ LocalDateTime startDate = null;
|
|
|
+ LocalDateTime endDate = DateUtil.parseLocalDateTime("2023-07-01 00:00:00");
|
|
|
+ BigDecimal seriveCharge = BigDecimal.ONE;
|
|
|
+
|
|
|
+
|
|
|
+ // 查出所有符合开票的数据
|
|
|
+ LambdaQueryWrapper<WmScorePackage> queryWrapper = Wrappers.<WmScorePackage>lambdaQuery()
|
|
|
+ .eq(WmScorePackage::getPackageType1, "1")
|
|
|
+ .eq(WmScorePackage::getPackageType2, "1")
|
|
|
+ .in(WmScorePackage::getScorePackageStatus, "4", "5")
|
|
|
+ .eq(WmScorePackage::getSettleStatus, "1")
|
|
|
+ .in(WmScorePackage::getTypeid, "3", "4")
|
|
|
+ .and(wrapper -> wrapper.isNull(WmScorePackage::getRelationScoreId)
|
|
|
+ .or(wrapper1 -> wrapper1.eq(WmScorePackage::getRelationScoreId, "")));
|
|
|
+ if (CollUtil.isNotEmpty(deptList)) {
|
|
|
+ queryWrapper.in(WmScorePackage::getSendPackageDeptId, deptList);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<WmScorePackage> scorePackages = scorePackageMapper.selectList(queryWrapper);
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(scorePackages)) {
|
|
|
+ Set<String> packageIds = scorePackages.stream().map(WmScorePackage::getId).collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 查询积分包对应的结算成功的数据
|
|
|
+ LambdaQueryWrapper<WmScorePackageSettleNote> queryWrapper1 = Wrappers.<WmScorePackageSettleNote>lambdaQuery()
|
|
|
+ .in(WmScorePackageSettleNote::getPackageId, packageIds)
|
|
|
+ .eq(WmScorePackageSettleNote::getSettleNoteStatus, "1");
|
|
|
+ if (startDate != null) {
|
|
|
+ queryWrapper1.gt(WmScorePackageSettleNote::getNotifyTime, startDate);
|
|
|
+ }
|
|
|
+ if (endDate != null) {
|
|
|
+ queryWrapper1.lt(WmScorePackageSettleNote::getNotifyTime, endDate);
|
|
|
+ }
|
|
|
+ List<WmScorePackageSettleNote> settleNotes = scorePackageSettleNoteMapper.selectList(queryWrapper1);
|
|
|
+ if (CollUtil.isNotEmpty(settleNotes)) {
|
|
|
+ Map<String, List<WmScorePackageSettleNote>> settlePackageMap = settleNotes.stream().collect(Collectors.groupingBy(WmScorePackageSettleNote::getPackageId));
|
|
|
+ // 积分包过滤,只要结算成功的数据
|
|
|
+ List<WmScorePackage> filterPackages = scorePackages.stream().filter(scorePackage -> {
|
|
|
+ List<WmScorePackageSettleNote> settleNotes1 = settlePackageMap.get(scorePackage.getId());
|
|
|
+ if (CollUtil.isNotEmpty(settleNotes1)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ filterPackages.forEach(scorePackage -> {
|
|
|
+ Integer deptId = Integer.valueOf(scorePackage.getSendPackageDeptId());
|
|
|
+ Integer totalScore = scorePackage.getScore();
|
|
|
+ // 存入开票表中
|
|
|
+ // 计算开票金额
|
|
|
+ // 开票金额 = 开票积分 * (服务费率/100)
|
|
|
+ BigDecimal invoiceAmount = seriveCharge.divide(new BigDecimal("100.00"))
|
|
|
+ .multiply(BigDecimal.valueOf(totalScore)).setScale(2, RoundingMode.HALF_EVEN);
|
|
|
+ // 保存开票信息
|
|
|
+ SysDeptInvoice deptInvoice = new SysDeptInvoice();
|
|
|
+ deptInvoice.setDeptId(deptId);
|
|
|
+ deptInvoice.setInvoiceType(InvoiceType.GENERAL);
|
|
|
+ deptInvoice.setAddress("");
|
|
|
+ deptInvoice.setAddresseeName("");
|
|
|
+ deptInvoice.setAddresseePhone("");
|
|
|
+ deptInvoice.setApprovalStatus(InvoiceApprovalStatus.PASSED);
|
|
|
+ deptInvoice.setRelationPackageNumber(1);
|
|
|
+ deptInvoice.setRelationPackageScore(totalScore);
|
|
|
+ deptInvoice.setInvoiceAmount(invoiceAmount);
|
|
|
+ deptInvoiceMapper.insert(deptInvoice);
|
|
|
+
|
|
|
+ // 保存开票积分包关联信息
|
|
|
+ SysDeptInvoiceRelation invoiceRelation = new SysDeptInvoiceRelation();
|
|
|
+ invoiceRelation.setDeptId(Integer.valueOf(scorePackage.getDeptId()));
|
|
|
+ invoiceRelation.setInvoiceId(deptInvoice.getId());
|
|
|
+ invoiceRelation.setInvoiceStatus(InvoiceStatus.PASSED);
|
|
|
+ invoiceRelation.setCreateUser(1);
|
|
|
+ invoiceRelation.setPackageId(scorePackage.getId());
|
|
|
+ deptInvoiceRelationMapper.insert(invoiceRelation);
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|