|
|
@@ -0,0 +1,136 @@
|
|
|
+package com.sqx.modules.exportExecl.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.sqx.common.utils.DateUtils;
|
|
|
+import com.sqx.common.utils.PageUtils;
|
|
|
+import com.sqx.common.utils.Result;
|
|
|
+import com.sqx.modules.exportExecl.mapper.ExportJobMapper;
|
|
|
+import com.sqx.modules.exportExecl.model.ExportJob;
|
|
|
+import com.sqx.modules.exportExecl.service.ExportJobService;
|
|
|
+import com.sqx.modules.order.dao.AppOrderDao;
|
|
|
+import com.sqx.modules.order.entity.TbOrder;
|
|
|
+import com.sqx.modules.order.service.AppOrderService;
|
|
|
+import com.sqx.modules.utils.excel.ExcelData;
|
|
|
+import com.sqx.modules.utils.excel.ExportExcelUtils;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.util.IOUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.BufferedInputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Paths;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Api(tags={"管理端-导出"})
|
|
|
+@RestController
|
|
|
+@RequestMapping("/admin/export")
|
|
|
+public class exportExeclController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AppOrderDao appOrderDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExportJobMapper exportJobMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ExportJobService exportJobService;
|
|
|
+
|
|
|
+ @GetMapping("excelOrder")
|
|
|
+ @ApiOperation("导出卡密列表")
|
|
|
+ public Result excelOrder(Integer status, String phone, Long shopId, String userName,
|
|
|
+ String orderNumber, Integer orderType, String shopName, String riderPhone,
|
|
|
+ String startTime, String endTime, String userId,HttpServletResponse response) throws Exception{
|
|
|
+ Integer size = appOrderDao.excelAllOrderAdminCount( status, phone, shopId, userName, orderNumber, orderType,
|
|
|
+ shopName, riderPhone,startTime,endTime);
|
|
|
+ int i=10000;
|
|
|
+ if(size>i){
|
|
|
+ return Result.error("导出总数不能超过"+i+",请添加筛选条件");
|
|
|
+ }
|
|
|
+ StringBuffer stringBuffer=new StringBuffer();
|
|
|
+ if(status!=null){stringBuffer.append("状态:"+status+";");}
|
|
|
+ if(phone!=null&&phone!=""){stringBuffer.append("手机号:"+phone+";");}
|
|
|
+// if(shopId!=null){stringBuffer.append(":"+shopId+";");}
|
|
|
+ if(userName!=null&&userName!=""){stringBuffer.append("昵称:"+userName+";");}
|
|
|
+ if(orderNumber!=null&&orderNumber!=""){stringBuffer.append("订单号:"+orderNumber+";");}
|
|
|
+ if(orderType!=null){stringBuffer.append("订单类型:"+orderType+";");}
|
|
|
+ if(shopName!=null&&shopName!=""){stringBuffer.append("商铺名称:"+shopName+";");}
|
|
|
+ if(riderPhone!=null&&riderPhone!=""){stringBuffer.append("骑手手机号:"+riderPhone+";");}
|
|
|
+ if(startTime!=null&&startTime!=""){stringBuffer.append("开始时间:"+startTime+";");}
|
|
|
+ if(endTime!=null&&endTime!=""){stringBuffer.append("结束时间:"+endTime+";");}
|
|
|
+
|
|
|
+ ExportJob exportJob =new ExportJob();
|
|
|
+ exportJob.setFlag(0);
|
|
|
+ exportJob.setFileType("order");
|
|
|
+ exportJob.setConditionDetail(stringBuffer.toString());
|
|
|
+ exportJob.setConditions(","+(status==null?"":status)+","+phone+","+(shopId==null?"":shopId)+","+userName+","+orderNumber+","
|
|
|
+ +(orderType==null?"":orderType)+","+shopName+","
|
|
|
+ +riderPhone+","+startTime+","+endTime);
|
|
|
+ LocalDateTime localDateTime = LocalDateTime.now();
|
|
|
+ String time=localDateTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"));
|
|
|
+ exportJob.setFileName(time+"订单列表.xlsx");
|
|
|
+ exportJob.setUserId(userId);
|
|
|
+ int a=exportJobMapper.insert(exportJob);
|
|
|
+ if (a==1){
|
|
|
+ return Result.success("新增导出计划成功");
|
|
|
+ }else{
|
|
|
+ return Result.error("新增导出计划失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 任意文件读取/下载
|
|
|
+ @ApiOperation(value = "查询下载列表")
|
|
|
+ @GetMapping("listByUser")
|
|
|
+ public Result List(String userId,String state,String startTime,String endTime,Integer curretPage,Integer pageSize) throws IOException {
|
|
|
+
|
|
|
+ QueryWrapper queryWrapper=new QueryWrapper<ExportJob>();
|
|
|
+
|
|
|
+ queryWrapper.eq("user_id",userId);
|
|
|
+ if(StringUtils.hasText(state)){
|
|
|
+ queryWrapper.eq("flag",state);
|
|
|
+ }
|
|
|
+ if(StringUtils.hasText(startTime)){
|
|
|
+ queryWrapper.ge("create_time",startTime);
|
|
|
+ }
|
|
|
+ if(StringUtils.hasText(endTime)){
|
|
|
+ queryWrapper.le("create_time",endTime);
|
|
|
+ }
|
|
|
+ IPage<ExportJob> iPage=exportJobService.page(new Page<>(curretPage,pageSize),queryWrapper);
|
|
|
+ PageUtils pageUtils = new PageUtils(iPage);
|
|
|
+ return Result.success().put("data", pageUtils);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 任意文件读取/下载
|
|
|
+ @ApiOperation(value = "任意文件读取/下载")
|
|
|
+ @GetMapping("readBuffer")
|
|
|
+ public Result readbuffer(String filename,HttpServletResponse response) throws IOException {
|
|
|
+ if(filename.contains("..") || filename.contains("/")){
|
|
|
+ return Result.error("文件名异常");
|
|
|
+ }
|
|
|
+ try (InputStream inputStream = new BufferedInputStream(Files.newInputStream(Paths.get(filename)))){
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=" + filename);
|
|
|
+ response.setContentLength((int) Files.size(Paths.get(filename)));
|
|
|
+ response.setContentType("application/octet-stream");
|
|
|
+
|
|
|
+ // 使用 Apache Commons IO 库的工具方法将输入流中的数据拷贝到输出流中
|
|
|
+ IOUtils.copy(inputStream, response.getOutputStream());
|
|
|
+ return Result.success("文件下载成功");
|
|
|
+ }catch (IOException e){
|
|
|
+ log.error(e.getMessage());
|
|
|
+ return Result.error("文件下载失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|