silent 4 лет назад
Родитель
Сommit
7ed1b1b077

+ 75 - 0
ldt-core/src/main/java/org/springblade/common/utils/ExcelWriteUtil.java

@@ -0,0 +1,75 @@
+package org.springblade.common.utils;
+
+import cn.hutool.poi.excel.ExcelUtil;
+import cn.hutool.poi.excel.ExcelWriter;
+import lombok.Cleanup;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.reflect.FieldUtils;
+
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Author: Silent
+ * @Description
+ * @Date: Created in 10:51 2021/11/3
+ * @Modified By:
+ */
+@Slf4j
+public class ExcelWriteUtil {
+
+	/**
+	 * 写入Excel数据到流
+	 *
+	 * @param response   Http响应
+	 * @param fileName   文件名
+	 * @param excelTitle excel标题
+	 * @param titleMap   标题头
+	 * @param list       列表
+	 */
+	public static <T> void writeToResponse(final HttpServletResponse response, final String fileName, final String excelTitle, final Map<String, String> titleMap, final List<T> list, final Class<T> tClass) {
+		try {
+			@Cleanup ExcelWriter writer = ExcelUtil.getWriter();
+			//写入标题
+			writer.merge(titleMap.size() - 1, excelTitle);
+			//写入标题解释
+			int i = 0;
+			for (T ele : list) {
+				Map<String, Object> keyValueMap = new HashMap<>();
+				//获取解释值
+				for (Map.Entry<String, String> entry : titleMap.entrySet()) {
+					try {
+						//获取字段值
+						Field declaredField = FieldUtils.getDeclaredField(tClass, entry.getKey(),true);
+						if(ObjectUtils.isEmpty(declaredField)){
+							declaredField = FieldUtils.getField(tClass, entry.getKey(),true);
+						}
+						//允许私有变量获取
+						keyValueMap.put(entry.getValue(), declaredField.get(ele));
+					} catch (Exception e) {
+						keyValueMap.put(entry.getValue(), "");
+						log.debug(e.getMessage());
+					}
+				}
+				//写入数据
+				if (i == 0) {
+					writer.writeRow(keyValueMap, true);
+				} else {
+					writer.writeRow(keyValueMap, false);
+				}
+				i++;
+			}
+			//设置响应头
+			response.setHeader("Content-Disposition", String.format("attachment;filename=%s%s", fileName, ".xls"));
+			@Cleanup ServletOutputStream outputStream = response.getOutputStream();
+			writer.flush(outputStream);
+		} catch (Exception e) {
+			log.error(e.getMessage());
+		}
+	}
+}

+ 52 - 7
ldt-core/src/main/java/org/springblade/ldt/bills/controller/PlatformBillsController.java

@@ -16,6 +16,8 @@
  */
 package org.springblade.ldt.bills.controller;
 
+import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
@@ -23,6 +25,12 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springblade.common.aop.core.TenantAop;
+import org.springblade.common.constant.Salesman;
+import org.springblade.common.utils.ExcelWriteUtil;
 import org.springblade.core.boot.ctrl.BladeController;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
@@ -37,13 +45,14 @@ import org.springblade.ldt.shop.service.IShopService;
 import org.springblade.ldt.user.service.ILoginUserService;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
 /**
- *  控制器
+ * 控制器
  *
  * @author BladeX
  * @since 2021-09-23
@@ -52,6 +61,7 @@ import java.util.Map;
 @AllArgsConstructor
 @RequestMapping("ldt_bills/platformbills")
 @Api(value = "", tags = "接口")
+@Slf4j
 public class PlatformBillsController extends BladeController {
 
 	private final IPlatformBillsService platformBillsService;
@@ -70,7 +80,7 @@ public class PlatformBillsController extends BladeController {
 	@ApiOperation(value = "详情", notes = "传入platformBills")
 	public R<PlatformBillsVO> detail(PlatformBills platformBills) {
 		PlatformBills detail = platformBillsService.getOne(Condition.getQueryWrapper(platformBills));
-		return R.data(PlatformBillsWrapper.build(loginUserService,shopService,mallService).entityVO(detail));
+		return R.data(PlatformBillsWrapper.build(loginUserService, shopService, mallService).entityVO(detail));
 	}
 
 	/**
@@ -79,13 +89,48 @@ public class PlatformBillsController extends BladeController {
 	@GetMapping("/list")
 	@ApiOperationSupport(order = 2)
 	@ApiOperation(value = "分页", notes = "传入platformBills")
-	public R<IPage<PlatformBillsVO>> list(PlatformBills platformBills, Query query, Date createTimeStart,Date createTimeEnd) {
+	public R<IPage<PlatformBillsVO>> list(PlatformBills platformBills, Query query, Date createTimeStart, Date createTimeEnd,
+											String key) {
 		QueryWrapper<PlatformBills> queryWrapper = Condition.getQueryWrapper(platformBills);
 		//添加创建时间条件
-		if(createTimeStart!=null && createTimeEnd!=null){
-			queryWrapper.lambda().between(PlatformBills::getCreateTime,createTimeStart,createTimeEnd);
+		if (createTimeStart != null && createTimeEnd != null) {
+			queryWrapper.lambda().between(PlatformBills::getCreateTime, createTimeStart, createTimeEnd);
+		}
+		//添加关键字key查询条件
+		if (StringUtils.isNotBlank(key)) {
+			queryWrapper.lambda().and(wq -> {
+				wq.eq(PlatformBills::getId, key);
+			});
+		}
+		return R.data(PlatformBillsWrapper.build(loginUserService, shopService, mallService).pageVO(platformBillsService.page(Condition.getPage(query), queryWrapper)));
+	}
+
+	/**
+	 * 生成列表
+	 */
+	@PostMapping("/generateList")
+	@ApiOperationSupport(order = 2)
+	@ApiOperation(value = "生成列表", notes = "传入withdrawRec")
+	@TenantAop(salesman = Salesman.roleName)
+	public void generateList(PlatformBills platformBills, Query query, Date createTimeStart, Date createTimeEnd,
+							 String key,
+							 @RequestParam String keyValue,
+							 HttpServletResponse response) {
+		try {
+			R<IPage<PlatformBillsVO>> page = this.list(platformBills, query, createTimeStart, createTimeEnd, key);
+			//判断是否为空
+			if (ObjectUtils.isNotEmpty(page) && ObjectUtils.isNotEmpty(page.getData()) && ObjectUtils.isNotEmpty(page.getData().getRecords())) {
+				//键值对
+				Map<String, String> titleMap = JSONObject.parseObject(keyValue, Map.class);
+				if (ObjectUtils.isNotEmpty(titleMap)) {
+					//写入到Excel
+					ExcelWriteUtil.writeToResponse(response, DateUtil.now(), "提现记录表", titleMap, page.getData().getRecords(), PlatformBillsVO.class);
+					return;
+				}
+			}
+		} catch (Exception e) {
+			log.error(e.getMessage());
 		}
-		return R.data(PlatformBillsWrapper.build(loginUserService,shopService,mallService).pageVO(platformBillsService.page(Condition.getPage(query), queryWrapper)));
 	}
 
 
@@ -95,7 +140,7 @@ public class PlatformBillsController extends BladeController {
 	@GetMapping("/censusPrice")
 	@ApiOperationSupport(order = 2)
 	@ApiOperation(value = "统计金额", notes = "统计金额")
-	public R<List<Map<String,Object>>> censusPrice() {
+	public R<List<Map<String, Object>>> censusPrice() {
 		return R.data(platformBillsService.listMaps(new QueryWrapper<PlatformBills>()
 			.select("sum(fee) as price,type as type")
 			.lambda().groupBy(PlatformBills::getType)));

+ 48 - 11
ldt-core/src/main/java/org/springblade/ldt/bills/controller/WithdrawRecController.java

@@ -16,6 +16,8 @@
  */
 package org.springblade.ldt.bills.controller;
 
+import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
@@ -23,9 +25,12 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springblade.common.aop.core.TenantAop;
 import org.springblade.common.constant.Salesman;
+import org.springblade.common.utils.ExcelWriteUtil;
 import org.springblade.core.boot.ctrl.BladeController;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
@@ -39,6 +44,7 @@ import org.springblade.ldt.shop.service.IShopService;
 import org.springblade.ldt.user.service.ILoginUserService;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 import java.util.Date;
 import java.util.Map;
@@ -53,6 +59,7 @@ import java.util.Map;
 @AllArgsConstructor
 @RequestMapping("ldt_bills/withdrawrec")
 @Api(value = "", tags = "接口")
+@Slf4j
 public class WithdrawRecController extends BladeController {
 
 	private final IWithdrawRecService withdrawRecService;
@@ -65,9 +72,9 @@ public class WithdrawRecController extends BladeController {
 	@GetMapping("/detail")
 	@ApiOperationSupport(order = 1)
 	@ApiOperation(value = "详情", notes = "传入withdrawRec")
-	@TenantAop(salesman=Salesman.roleName)
+	@TenantAop(salesman = Salesman.roleName)
 	public R<WithdrawRecVO> detail(WithdrawRec withdrawRec) {
-		return R.data(WithdrawRecWrapper.build(userService,shopService).entityVO(withdrawRecService.getOne(Condition.getQueryWrapper(withdrawRec))));
+		return R.data(WithdrawRecWrapper.build(userService, shopService).entityVO(withdrawRecService.getOne(Condition.getQueryWrapper(withdrawRec))));
 	}
 
 	/**
@@ -76,21 +83,51 @@ public class WithdrawRecController extends BladeController {
 	@GetMapping("/list")
 	@ApiOperationSupport(order = 2)
 	@ApiOperation(value = "分页", notes = "传入withdrawRec")
-	@TenantAop(salesman=Salesman.roleName)
-	public R<IPage<WithdrawRecVO>> list(WithdrawRec withdrawRec, Query query, Date createTimeStart, Date createTimeEnd,String key) {
+	@TenantAop(salesman = Salesman.roleName)
+	public R<IPage<WithdrawRecVO>> list(WithdrawRec withdrawRec, Query query, Date createTimeStart, Date createTimeEnd, String key) {
 		QueryWrapper<WithdrawRec> queryWrapper = Condition.getQueryWrapper(withdrawRec);
 		//添加创建时间条件
-		if(createTimeStart!=null && createTimeEnd!=null){
-			queryWrapper.lambda().between(WithdrawRec::getCreateTime,createTimeStart,createTimeEnd);
+		if (createTimeStart != null && createTimeEnd != null) {
+			queryWrapper.lambda().between(WithdrawRec::getCreateTime, createTimeStart, createTimeEnd);
 		}
 		//添加关键字key查询条件
-		if(StringUtils.isNotBlank(key)){
-			queryWrapper.lambda().and(wq->{
-				wq.eq(WithdrawRec::getReceiverAccountName,key);
+		if (StringUtils.isNotBlank(key)) {
+			queryWrapper.lambda().and(wq -> {
+				wq.eq(WithdrawRec::getReceiverAccountName, key)
+					.or().eq(WithdrawRec::getReceiverAccountNo, key)
+					.or().eq(WithdrawRec::getOrderId, key);
 			});
 		}
 		queryWrapper.lambda().orderByDesc(WithdrawRec::getCreateTime);
-		return R.data(WithdrawRecWrapper.build(userService,shopService).pageVO(withdrawRecService.page(Condition.getPage(query), queryWrapper)));
+		return R.data(WithdrawRecWrapper.build(userService, shopService).pageVO(withdrawRecService.page(Condition.getPage(query), queryWrapper)));
+	}
+
+	/**
+	 * 生成列表
+	 */
+	@PostMapping("/generateList")
+	@ApiOperationSupport(order = 2)
+	@ApiOperation(value = "生成列表", notes = "传入withdrawRec")
+	@TenantAop(salesman = Salesman.roleName)
+	public void generateList(WithdrawRec withdrawRec,Query query,Date createTimeStart,Date createTimeEnd,
+							 String key,
+							 @RequestParam String keyValue,
+							 HttpServletResponse response) {
+		try {
+			R<IPage<WithdrawRecVO>> page = this.list(withdrawRec, query, createTimeStart, createTimeEnd, key);
+			//判断是否为空
+			if (ObjectUtils.isNotEmpty(page) && ObjectUtils.isNotEmpty(page.getData()) && ObjectUtils.isNotEmpty(page.getData().getRecords())) {
+				//键值对
+				Map<String, String> titleMap = JSONObject.parseObject(keyValue, Map.class);
+				if (ObjectUtils.isNotEmpty(titleMap)) {
+					//写入到Excel
+					ExcelWriteUtil.writeToResponse(response, DateUtil.now(), "提现记录表", titleMap, page.getData().getRecords(), WithdrawRecVO.class);
+					return;
+				}
+			}
+		} catch (Exception e) {
+			log.error(e.getMessage());
+		}
 	}
 
 	/**
@@ -150,7 +187,7 @@ public class WithdrawRecController extends BladeController {
 	@GetMapping("/amount-statistical")
 	@ApiOperationSupport(order = 8)
 	@ApiOperation(value = "提现金额统计", notes = "提现金额统计")
-	public R<Map<String,Object>> amountStatistical() {
+	public R<Map<String, Object>> amountStatistical() {
 		return R.data(withdrawRecService.amountStatistical());
 	}