|
|
@@ -0,0 +1,193 @@
|
|
|
+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.jcraft.jsch.SftpException;
|
|
|
+import com.sqx.common.utils.PageUtils;
|
|
|
+import com.sqx.common.utils.Result;
|
|
|
+import com.sqx.common.utils.SftpUtil;
|
|
|
+import com.sqx.modules.common.service.CommonInfoService;
|
|
|
+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 io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.util.IOUtils;
|
|
|
+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.net.URLEncoder;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Paths;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Api(tags={"管理端-导出"})
|
|
|
+@RestController
|
|
|
+@RequestMapping("/admin/export")
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class ExportExeclController {
|
|
|
+
|
|
|
+ private final AppOrderDao appOrderDao;
|
|
|
+
|
|
|
+ private final ExportJobMapper exportJobMapper;
|
|
|
+
|
|
|
+ private final ExportJobService exportJobService;
|
|
|
+
|
|
|
+ private final CommonInfoService commonInfoService;
|
|
|
+
|
|
|
+ private final SftpUtil sftpUtil;
|
|
|
+
|
|
|
+ @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, String payStartTime, String payEndTime) throws Exception{
|
|
|
+ Integer size = appOrderDao.excelAllOrderAdminCount( status, phone, shopId, userName, orderNumber, orderType,
|
|
|
+ shopName, riderPhone,startTime,endTime,payStartTime,payEndTime);
|
|
|
+ //可导出最大数量
|
|
|
+ String count=commonInfoService.findOne(431).getValue();
|
|
|
+ if(size>Integer.parseInt(count)){
|
|
|
+ return Result.error("导出总数不能超过"+Integer.parseInt(count)+",请添加筛选条件");
|
|
|
+ }
|
|
|
+ if(!StringUtils.hasText(userId)){
|
|
|
+ return Result.error("用户id不能为空");
|
|
|
+ }
|
|
|
+ StringBuffer stringBuffer=new StringBuffer();
|
|
|
+ if(status!=null){stringBuffer.append("状态:"+getState(status)+";");}
|
|
|
+ if(phone!=null&&!phone.trim().equals("")){stringBuffer.append("手机号:"+phone+";");}
|
|
|
+// if(shopId!=null){stringBuffer.append(":"+shopId+";");}
|
|
|
+ if(userName!=null&&!userName.trim().equals("")){stringBuffer.append("昵称:"+userName+";");}
|
|
|
+ if(orderNumber!=null&&!orderNumber.trim().equals("")){stringBuffer.append("订单号:"+orderNumber+";");}
|
|
|
+ if(orderType!=null){stringBuffer.append("订单类型:"+(orderType==1?"到店取餐":(orderType==2?"骑手配送":"商家配送"))+";");}
|
|
|
+ if(shopName!=null&&!shopName.trim().equals("")){stringBuffer.append("商铺名称:"+shopName+";");}
|
|
|
+ if(riderPhone!=null&&!riderPhone.trim().equals("")){stringBuffer.append("骑手手机号:"+riderPhone+";");}
|
|
|
+ if(startTime!=null&&!startTime.trim().equals("")){stringBuffer.append("开始时间:"+startTime+";");}
|
|
|
+ if(endTime!=null&&!endTime.trim().equals("")){stringBuffer.append("结束时间:"+endTime+";");}
|
|
|
+ if(payStartTime!=null&&!payStartTime.trim().equals("")){stringBuffer.append("支付开始时间:"+payStartTime+";");}
|
|
|
+ if(payEndTime!=null&&!payEndTime.trim().equals("")){stringBuffer.append("支付结束时间:"+payEndTime+";");}
|
|
|
+
|
|
|
+ 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+","+payStartTime+","+payEndTime);
|
|
|
+ LocalDateTime localDateTime = LocalDateTime.now();
|
|
|
+ String time=localDateTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"));
|
|
|
+ exportJob.setFileName(time+"订单列表.xlsx");
|
|
|
+ exportJob.setUserId(userId);
|
|
|
+ exportJob.setCreateTime(new Date());
|
|
|
+ exportJob.setUpdateTime(new Date());
|
|
|
+ int a=exportJobMapper.insert(exportJob);
|
|
|
+ if (a==1){
|
|
|
+ return Result.success("新增导出计划成功");
|
|
|
+ }else{
|
|
|
+ return Result.error("新增导出计划失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @GetMapping("excelRecharge")
|
|
|
+ @ApiOperation("导出充值记录")
|
|
|
+ public Result excelRecharge(String rechargeOrder, String acount,String userId) throws Exception{
|
|
|
+ if(!StringUtils.hasText(userId)){
|
|
|
+ return Result.error("用户id不能为空");
|
|
|
+ }
|
|
|
+ StringBuffer stringBuffer=new StringBuffer();
|
|
|
+ if(rechargeOrder!=null&&rechargeOrder!=""){stringBuffer.append("充值订单号:"+rechargeOrder+";");}
|
|
|
+ if(acount!=null&&acount!=""){stringBuffer.append("被充值账号:"+acount+";");}
|
|
|
+
|
|
|
+ ExportJob exportJob =new ExportJob();
|
|
|
+ exportJob.setFlag(0);
|
|
|
+ exportJob.setFileType("recharge");
|
|
|
+ exportJob.setConditionDetail(stringBuffer.toString());
|
|
|
+ exportJob.setConditions(","+rechargeOrder+","+acount);
|
|
|
+ LocalDateTime localDateTime = LocalDateTime.now();
|
|
|
+ String time=localDateTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"));
|
|
|
+ exportJob.setFileName(time+"充值记录.xlsx");
|
|
|
+ exportJob.setCreateTime(new Date());
|
|
|
+ exportJob.setUpdateTime(new Date());
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ queryWrapper.orderByDesc("create_time");
|
|
|
+ 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 void readbuffer(String filename,HttpServletResponse response) throws IOException {
|
|
|
+ if(filename.contains("..") || filename.contains("/")){
|
|
|
+ throw new IOException("文件名异常");
|
|
|
+ }
|
|
|
+ String value=commonInfoService.findOne(430).getValue()==null?"":commonInfoService.findOne(430).getValue();
|
|
|
+ sftpUtil.login();
|
|
|
+ try {
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ // 下载文件的默认名称
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "utf-8"));
|
|
|
+ sftpUtil.downloadStream(value,filename,response.getOutputStream());
|
|
|
+ log.info("文件下载成功");
|
|
|
+ }catch (IOException | SftpException e){
|
|
|
+ log.error(e.getMessage());
|
|
|
+ log.error("文件下载失败");
|
|
|
+ }finally {
|
|
|
+ if (sftpUtil.isConnected()){
|
|
|
+ sftpUtil.logout();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // '订单状态 0待结算 1待支付 2直接购买(未支付) 7商家待接单 8商家拒绝接单 6制作中 3待取餐/派送中 4已完成 5已取消 ',
|
|
|
+ private String getState(Integer state){
|
|
|
+ switch (state){
|
|
|
+ case 1: return "待支付";
|
|
|
+ case 2: return "未支付";
|
|
|
+ case 3: return "待取餐";
|
|
|
+ case 4: return "已完成";
|
|
|
+ case 5: return "已取消";
|
|
|
+ case 6: return "制作中";
|
|
|
+ case 7: return "商家待接单";
|
|
|
+ case 8: return "商家拒绝接单";
|
|
|
+ case 0: return "待结算";
|
|
|
+ default: return state+"";
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|