xiari 1 year ago
parent
commit
94f9966af1

+ 106 - 0
ruoyi-modules/ruoyi-backstage/src/test/java/org/dromara/backstage/mq/KafkaProducerTest.java

@@ -1,17 +1,123 @@
 package org.dromara.backstage.mq;
 
+import cn.hutool.core.codec.Base64;
+import cn.hutool.core.collection.CollectionUtil;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import lombok.Data;
+import org.dromara.backstage.consumption.domain.bo.HandImportExcelConsumeBo;
+import org.dromara.backstage.payment.domain.PtUserAccount;
+import org.dromara.backstage.payment.mapper.PtUserAccountMapper;
+import org.dromara.backstage.payment.service.IPtUserAccountService;
+import org.dromara.common.core.utils.StringUtils;
+import org.dromara.common.excel.core.ExcelResult;
+import org.dromara.common.excel.utils.ExcelUtil;
+import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 
+import java.io.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
 @SpringBootTest
 public class KafkaProducerTest {
 
     @Autowired
     private KafkaNormalProducer kafkaProcedurer;
 
+    @Autowired
+    private PtUserAccountMapper userAccountMapper;
+
     // @Test
     // public void send()
     // {
     //     kafkaProcedurer.sendKafkaMessage("ykt_local_listener", "test message2");
     // }
+
+
+    // 导出补消费Excel
+    @Test
+    public void exportExcel() throws FileNotFoundException {
+        //解析Excel 文件
+        File file = new File("C:\\Users\\LENOVO\\Desktop\\一卡通\\未刷卡补消费\\补消费.xlsx");
+        //file 获取输入流
+        ExcelResult<ParamBo> excelResult = ExcelUtil.importExcel(new FileInputStream(file), ParamBo.class, true);
+        List<ParamBo> volist = excelResult.getList();
+        List<ExportExcelBo> list = new ArrayList<>();
+        for (ParamBo paramBo : volist) {
+            ExportExcelBo bo = new ExportExcelBo();
+            bo.setName(paramBo.getName());
+            bo.setPhone(paramBo.getPhone());
+            bo.setConsumeDate(paramBo.getConsumeDate());
+            bo.setTermNo("56");
+            bo.setConsumeMoney("10");
+            LambdaQueryWrapper<PtUserAccount> queryWrapper = new LambdaQueryWrapper<>();
+
+            if(StringUtils.isEmpty(paramBo.getName())){
+                paramBo.setName("");
+            }
+            if(StringUtils.isNotBlank(paramBo.getPhone()) && StringUtils.isNotBlank(paramBo.getName())){
+                queryWrapper.and(wrapper -> wrapper.eq(PtUserAccount::getPhone, Base64.encode(paramBo.getPhone())).or().eq(PtUserAccount::getRealName, paramBo.getName()));
+            }else if (StringUtils.isNotBlank(paramBo.getPhone())){
+                queryWrapper.eq(PtUserAccount::getPhone, Base64.encode(paramBo.getPhone()));
+            }else if (StringUtils.isNotBlank(paramBo.getName())){
+                queryWrapper.eq(PtUserAccount::getRealName, paramBo.getName());
+            }else {
+                bo.setRemark("未找到该用户");
+                list.add(bo);
+                continue;
+            }
+            List<PtUserAccount> ptUserAccounts = userAccountMapper.selectList(queryWrapper);
+            if (CollectionUtil.isEmpty(ptUserAccounts)){
+                bo.setRemark("未找到该用户");
+            }else if(ptUserAccounts.size() == 1){
+                PtUserAccount ptUserAccount = ptUserAccounts.get(0);
+                bo.setUserNumb(ptUserAccount.getUserNumb());
+            }else {
+                bo.setRemark("该用户有多个账号,请自行检查");
+            }
+
+            list.add(bo);
+        }
+        FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\LENOVO\\Desktop\\一卡通\\未刷卡补消费\\导入补消费.xlsx");
+        ExcelUtil.exportExcel(list, "补消费", ExportExcelBo.class, fileOutputStream);
+
+    }
+
+
+
+
+    @Data
+    public static class ParamBo implements Serializable {
+        @Serial
+        private static final long serialVersionUID = 1L;
+        @ExcelProperty(value = "日期")
+        private Date consumeDate;
+        @ExcelProperty(value = "姓名")
+        private String name;
+        @ExcelProperty(value = "电话")
+        private String phone;
+    }
+
+    @Data
+    public static class ExportExcelBo implements Serializable {
+        @Serial
+        private static final long serialVersionUID = 1L;
+        @ExcelProperty(value = "姓名")
+        private String name;
+        @ExcelProperty(value = "电话")
+        private String phone;
+        @ExcelProperty(value = "学工号")
+        private String userNumb;
+        @ExcelProperty(value = "消费日期")
+        private Date consumeDate;
+        @ExcelProperty(value = "消费金额")
+        private String consumeMoney;
+        @ExcelProperty(value = "设备机号")
+        private String termNo;
+        @ExcelProperty(value = "备注")
+        private String remark;
+    }
 }