|
@@ -4,6 +4,8 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.kdan.compdf.dto.AddFreePlanDTO;
|
|
|
import cn.kdan.compdf.dto.Asset;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.kdan.compdf.config.ExcelWidthStyleStrategy;
|
|
|
import cn.kdan.compdf.dto.PlanStatisticsDTO;
|
|
|
import cn.kdan.compdf.entity.BackgroundUserBalance;
|
|
|
import cn.kdan.compdf.mapper.BackgroundUserBalanceMapper;
|
|
@@ -11,20 +13,29 @@ import cn.kdan.compdf.service.BackgroundUserBalanceService;
|
|
|
import cn.kdan.compdf.service.BackgroundUserService;
|
|
|
import cn.kdan.compdf.vo.BackgroundUserBalanceVO;
|
|
|
import cn.kdan.compdf.vo.BackgroundUserPackageBalanceVO;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.util.MapUtils;
|
|
|
+import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.tomcat.util.http.fileupload.IOUtils;
|
|
|
import org.assertj.core.util.Lists;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.*;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.time.ZoneId;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
@@ -113,6 +124,61 @@ public class BackgroundUserBalanceServiceImpl extends ServiceImpl<BackgroundUser
|
|
|
return backgroundUserBalanceVOPage;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 账户消费充值记录导出
|
|
|
+ * @param userId 用户id
|
|
|
+ * @param response response
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void exportBalanceRecordList(Long userId, HttpServletResponse response) {
|
|
|
+ LambdaQueryWrapper<BackgroundUserBalance> eq = new LambdaQueryWrapper<BackgroundUserBalance>()
|
|
|
+ .eq(BackgroundUserBalance::getUserId, userId)
|
|
|
+ .orderByDesc(BackgroundUserBalance::getCreateDate);
|
|
|
+ List<BackgroundUserBalance> backgroundUserBalanceList = this.baseMapper.selectList(eq);
|
|
|
+ // 处理返回数据
|
|
|
+ List<BackgroundUserBalanceVO> backgroundUserBalanceVOList = new ArrayList<>();
|
|
|
+ if (CollectionUtil.isNotEmpty(backgroundUserBalanceList)) {
|
|
|
+ backgroundUserBalanceList.forEach(c -> {
|
|
|
+ BackgroundUserBalanceVO backgroundUserBalanceVO = new BackgroundUserBalanceVO();
|
|
|
+ BeanUtil.copyProperties(c, backgroundUserBalanceVO);
|
|
|
+ if (c.getChangeType() == 1) {
|
|
|
+ backgroundUserBalanceVO.setBalanceChange("+" + c.getBalanceChange());
|
|
|
+ } else {
|
|
|
+ backgroundUserBalanceVO.setBalanceChange("-" + c.getBalanceChange());
|
|
|
+ }
|
|
|
+ backgroundUserBalanceVOList.add(backgroundUserBalanceVO);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 写入响应导出
|
|
|
+ try {
|
|
|
+ String fileName = URLEncoder.encode("Processing Files Balance (" + DateUtil.date().toString().replaceAll(":", "-") + ")", "UTF-8").replaceAll("\\+", "%20");
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
|
|
+ EasyExcel.write(response.getOutputStream(), BackgroundUserBalanceVO.class)
|
|
|
+ .registerWriteHandler(new ExcelWidthStyleStrategy())
|
|
|
+ .autoCloseStream(Boolean.FALSE)
|
|
|
+ .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
|
|
+ .sheet("Processing Files Balance")
|
|
|
+ .doWrite(backgroundUserBalanceVOList);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 重置response
|
|
|
+ response.reset();
|
|
|
+ response.setContentType("application/json");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ Map<String, String> map = MapUtils.newHashMap();
|
|
|
+ map.put("status", "failure");
|
|
|
+ map.put("message", "下载文件失败" + e.getMessage());
|
|
|
+ try {
|
|
|
+ response.getWriter().println(JSON.toJSONString(map));
|
|
|
+ } catch (IOException ioException) {
|
|
|
+ ioException.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void planSync(List<PlanStatisticsDTO> list) {
|
|
|
assert list != null : "Dashboard同步数据为空";
|