Browse Source

订单管理导出数据

yanliming 4 years ago
parent
commit
352068e3f1

+ 249 - 106
web/src/main/java/com/jpsoft/bus/modules/base/controller/OrderInfoController.java

@@ -1,6 +1,7 @@
 package com.jpsoft.bus.modules.base.controller;
 package com.jpsoft.bus.modules.base.controller;
 
 
 import com.github.pagehelper.Page;
 import com.github.pagehelper.Page;
+import com.jpsoft.bus.config.OSSConfig;
 import com.jpsoft.bus.modules.base.dto.OrderInfoDTO;
 import com.jpsoft.bus.modules.base.dto.OrderInfoDTO;
 import com.jpsoft.bus.modules.bus.entity.*;
 import com.jpsoft.bus.modules.bus.entity.*;
 import com.jpsoft.bus.modules.bus.service.*;
 import com.jpsoft.bus.modules.bus.service.*;
@@ -8,16 +9,25 @@ import com.jpsoft.bus.modules.common.dto.MessageResult;
 import com.jpsoft.bus.modules.common.dto.Sort;
 import com.jpsoft.bus.modules.common.dto.Sort;
 import com.jpsoft.bus.modules.base.entity.OrderInfo;
 import com.jpsoft.bus.modules.base.entity.OrderInfo;
 import com.jpsoft.bus.modules.base.service.OrderInfoService;
 import com.jpsoft.bus.modules.base.service.OrderInfoService;
+import com.jpsoft.bus.modules.common.utils.OSSUtil;
 import com.jpsoft.bus.modules.common.utils.PojoUtils;
 import com.jpsoft.bus.modules.common.utils.PojoUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.*;
@@ -56,6 +66,9 @@ public class OrderInfoController {
     @Autowired
     @Autowired
     private CompanyInfoService companyInfoService;
     private CompanyInfoService companyInfoService;
 
 
+    @Autowired
+    private OSSConfig ossConfig;
+
 
 
     @ApiOperation(value="创建空记录")
     @ApiOperation(value="创建空记录")
     @GetMapping("create")
     @GetMapping("create")
@@ -225,149 +238,279 @@ public class OrderInfoController {
 
 
     @ApiOperation(value="列表")
     @ApiOperation(value="列表")
     @RequestMapping(value = "pageList",method = RequestMethod.POST)
     @RequestMapping(value = "pageList",method = RequestMethod.POST)
-    public MessageResult<Map> pageList(
+    public MessageResult<Object> pageList(
             String companyId,String licensePlateNumber,String outOrderNo,String transactionId,
             String companyId,String licensePlateNumber,String outOrderNo,String transactionId,
             String shiftId,String createTimeRanges,String payTimeRanges,Integer payStatus,
             String shiftId,String createTimeRanges,String payTimeRanges,Integer payStatus,
             @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
             @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
             @RequestParam(value="pageSize",defaultValue="20") int pageSize,
             @RequestParam(value="pageSize",defaultValue="20") int pageSize,
+            @RequestParam(value = "exportFlag", defaultValue = "false") Boolean exportFlag,
             @RequestAttribute String subject){
             @RequestAttribute String subject){
 
 
         //当前用户ID
         //当前用户ID
         System.out.println(subject);
         System.out.println(subject);
 
 
-        MessageResult<Map> msgResult = new MessageResult<>();
+        MessageResult<Object> msgResult = new MessageResult<>();
 
 
-        Map<String,Object> searchParams = new HashMap<>();
+        try {
 
 
-        List<Sort> sortList = new ArrayList<>();
-        sortList.add(new Sort("a.create_time","desc"));
+            Map<String, Object> searchParams = new HashMap<>();
 
 
-        if (StringUtils.isNotEmpty(companyId)) {
-            searchParams.put("companyId",companyId);
-        }
+            List<Sort> sortList = new ArrayList<>();
+            sortList.add(new Sort("a.create_time", "desc"));
 
 
-        if (StringUtils.isNotEmpty(licensePlateNumber)) {
-            searchParams.put("licensePlateNumber","%"+licensePlateNumber+"%");
-        }
+            if (StringUtils.isNotEmpty(companyId)) {
+                searchParams.put("companyId", companyId);
+            }
 
 
-        if (StringUtils.isNotEmpty(outOrderNo)) {
-            searchParams.put("outOrderNo","%"+outOrderNo+"%");
-        }
+            if (StringUtils.isNotEmpty(licensePlateNumber)) {
+                searchParams.put("licensePlateNumber", "%" + licensePlateNumber + "%");
+            }
 
 
-        if (StringUtils.isNotEmpty(transactionId)) {
-            searchParams.put("transactionId","%"+transactionId+"%");
-        }
+            if (StringUtils.isNotEmpty(outOrderNo)) {
+                searchParams.put("outOrderNo", "%" + outOrderNo + "%");
+            }
 
 
-        if (StringUtils.isNotEmpty(shiftId)) {
-            searchParams.put("shiftId",shiftId);
-        }
+            if (StringUtils.isNotEmpty(transactionId)) {
+                searchParams.put("transactionId", "%" + transactionId + "%");
+            }
 
 
-        if (payStatus!=null) {
-            searchParams.put("payStatus",payStatus);
-        }
+            if (StringUtils.isNotEmpty(shiftId)) {
+                searchParams.put("shiftId", shiftId);
+            }
 
 
-        if(StringUtils.isNotEmpty(createTimeRanges)){
-            String[] timeRangeArray = createTimeRanges.split(",");
-            String createBeginTime = "";
-            String createEndTime = "";
-            if (timeRangeArray.length == 1) {
-                createBeginTime = timeRangeArray[0];
-                createBeginTime+=" 00:00:00";
-            } else if (timeRangeArray.length == 2) {
-                createBeginTime = timeRangeArray[0];
-                createEndTime = timeRangeArray[1];
-                createBeginTime+=" 00:00:00";
-                createEndTime+=" 23:59:59";
+            if (payStatus != null) {
+                searchParams.put("payStatus", payStatus);
             }
             }
 
 
-            searchParams.put("createBeginTime", createBeginTime);
-            searchParams.put("createEndTime", createEndTime);
-        }
+            if (StringUtils.isNotEmpty(createTimeRanges)) {
+                String[] timeRangeArray = createTimeRanges.split(",");
+                String createBeginTime = "";
+                String createEndTime = "";
+                if (timeRangeArray.length == 1) {
+                    createBeginTime = timeRangeArray[0];
+                    createBeginTime += " 00:00:00";
+                } else if (timeRangeArray.length == 2) {
+                    createBeginTime = timeRangeArray[0];
+                    createEndTime = timeRangeArray[1];
+                    createBeginTime += " 00:00:00";
+                    createEndTime += " 23:59:59";
+                }
 
 
-        if(StringUtils.isNotEmpty(payTimeRanges)){
-            String[] timeRangeArray = payTimeRanges.split(",");
-            String payBeginTime = "";
-            String payEndTime = "";
-            if (timeRangeArray.length == 1) {
-                payBeginTime = timeRangeArray[0];
-                payBeginTime+=" 00:00:00";
-            } else if (timeRangeArray.length == 2) {
-                payBeginTime = timeRangeArray[0];
-                payEndTime = timeRangeArray[1];
-                payBeginTime+=" 00:00:00";
-                payEndTime+=" 23:59:59";
+                searchParams.put("createBeginTime", createBeginTime);
+                searchParams.put("createEndTime", createEndTime);
             }
             }
 
 
-            searchParams.put("payBeginTime", payBeginTime);
-            searchParams.put("payEndTime", payEndTime);
-        }
+            if (StringUtils.isNotEmpty(payTimeRanges)) {
+                String[] timeRangeArray = payTimeRanges.split(",");
+                String payBeginTime = "";
+                String payEndTime = "";
+                if (timeRangeArray.length == 1) {
+                    payBeginTime = timeRangeArray[0];
+                    payBeginTime += " 00:00:00";
+                } else if (timeRangeArray.length == 2) {
+                    payBeginTime = timeRangeArray[0];
+                    payEndTime = timeRangeArray[1];
+                    payBeginTime += " 00:00:00";
+                    payEndTime += " 23:59:59";
+                }
 
 
+                searchParams.put("payBeginTime", payBeginTime);
+                searchParams.put("payEndTime", payEndTime);
+            }
 
 
-        Page<OrderInfo> page = orderInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
-
-        Page<OrderInfoDTO> pageDto = new Page<>();
-
-        for (OrderInfo orderInfo:page) {
-            OrderInfoDTO dto = new OrderInfoDTO();
-            dto.setId(orderInfo.getId());
-            dto.setTotalFee(orderInfo.getTotalFee());
-            dto.setBody(orderInfo.getBody());
-            dto.setPayFee(orderInfo.getPayFee());
-            dto.setPayStatus(orderInfo.getPayStatus());
-            dto.setPayName(orderInfo.getPayName());
-            dto.setPayTime(orderInfo.getPayTime());
-            dto.setCreateTime(orderInfo.getCreateTime());
-            dto.setOutOrderNo(orderInfo.getOutOrderNo());
-            dto.setTransactionId(orderInfo.getTransactionId());
-            dto.setTicketType(orderInfo.getTicketType());
-            dto.setGoodsTicket(orderInfo.getGoodsTicket());
-
-            PassengerInfo passengerInfo = passengerInfoService.get(orderInfo.getPassengerId());
-
-            if(passengerInfo!=null){
-                ShiftInfo shiftInfo = shiftInfoService.get(passengerInfo.getVehicleShiftId());
-                if(shiftInfo!=null){
-                    DriverInfo driverInfo = driverInfoService.get(shiftInfo.getDriverId());
-                    if(driverInfo!=null){
-                        dto.setDriverName(driverInfo.getName());
-                    }
-                    VehicleInfo vehicleInfo = vehicleInfoService.get(shiftInfo.getVehicleId());
-                    if(vehicleInfo!=null){
-                        dto.setLicensePlateNumber(vehicleInfo.getLicensePlateNumber());
-                        CompanyInfo companyInfo = companyInfoService.get(vehicleInfo.getCompanyId());
-                        if(companyInfo!=null){
-                            dto.setCompanyName(companyInfo.getName());
+
+            Page<OrderInfo> page = orderInfoService.pageSearch(searchParams, pageIndex, pageSize, true, sortList);
+
+            List<Map> mapList = new ArrayList<>();
+
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+
+            for (OrderInfo orderInfo : page) {
+
+                Map<String, Object> map = new HashMap<>();
+
+                map.put("id", orderInfo.getId());
+                map.put("totalFee", orderInfo.getTotalFee());
+                map.put("body", orderInfo.getBody());
+                map.put("payFee", orderInfo.getPayFee());
+                map.put("payStatus", orderInfo.getPayStatus());
+                if(orderInfo.getPayStatus()==10){
+                    map.put("payStatusN", "未支付");
+                }
+                else if(orderInfo.getPayStatus()==20){
+                    map.put("payStatusN","已支付");
+                }
+                else if(orderInfo.getPayStatus()==40){
+                    map.put("payStatusN", "已退款");
+                }
+                else{
+                    map.put("payStatusN", "");
+                }
+
+                map.put("payName", orderInfo.getPayName());
+
+                if(("wechat").equals(orderInfo.getPayName())){
+                    map.put("payNameN", "微信");
+                }
+                else if(("alipay").equals(orderInfo.getPayName())){
+                    map.put("payNameN", "支付宝");
+                }
+                else if(("cash").equals(orderInfo.getPayName())){
+                    map.put("payNameN", "现金");
+                }
+                else if(("ticket").equals(orderInfo.getPayName())){
+                    map.put("payNameN", "车票");
+                }
+                else{
+                    map.put("payNameN", "");
+                }
+
+                if(orderInfo.getPayTime()!=null) {
+                    map.put("payTime", sdf.format(orderInfo.getPayTime()));
+                }
+                else{
+                    map.put("payTime", "");
+                }
+                if(orderInfo.getCreateTime()!=null){
+                    map.put("createTime",  sdf.format(orderInfo.getCreateTime()));
+                }
+                else{
+                    map.put("createTime", "");
+                }
+
+                map.put("outOrderNo", orderInfo.getOutOrderNo());
+                map.put("transactionId", orderInfo.getTransactionId());
+                map.put("ticketType", orderInfo.getTicketType());
+                if(("1").equals(orderInfo.getTicketType())){
+                    map.put("ticketTypeN", "儿童票");
+                }
+                else if(("2").equals(orderInfo.getTicketType())){
+                    map.put("ticketTypeN", "成人票");
+                }
+                else{
+                    map.put("ticketTypeN", "");
+                }
+
+                map.put("goodsTicketN", orderInfo.getGoodsTicket());
+
+
+                PassengerInfo passengerInfo = passengerInfoService.get(orderInfo.getPassengerId());
+
+
+                if (passengerInfo != null) {
+                    ShiftInfo shiftInfo = shiftInfoService.get(passengerInfo.getVehicleShiftId());
+                    if (shiftInfo != null) {
+                        DriverInfo driverInfo = driverInfoService.get(shiftInfo.getDriverId());
+                        if (driverInfo != null) {
+                            map.put("driverName", driverInfo.getName());
+                        }
+                        VehicleInfo vehicleInfo = vehicleInfoService.get(shiftInfo.getVehicleId());
+                        if (vehicleInfo != null) {
+                            map.put("licensePlateNumber", vehicleInfo.getLicensePlateNumber());
+                            CompanyInfo companyInfo = companyInfoService.get(vehicleInfo.getCompanyId());
+                            if (companyInfo != null) {
+                                map.put("companyName", companyInfo.getName());
+                            }
+                        }
+                        RouteInfo routeInfo = routeInfoService.get(shiftInfo.getRouteId());
+                        if (routeInfo != null) {
+                            map.put("routeName", routeInfo.getName());
+                        }
+                        StationInfo upStation = stationInfoService.get(passengerInfo.getUpStationId());
+                        if (upStation != null) {
+                            map.put("upStationName", upStation.getName());
+                        }
+                        StationInfo downStation = stationInfoService.get(passengerInfo.getDownStationId());
+                        if (downStation != null) {
+                            map.put("downStationName", downStation.getName());
                         }
                         }
-                    }
-                    RouteInfo routeInfo = routeInfoService.get(shiftInfo.getRouteId());
-                    if(routeInfo!=null){
-                        dto.setRouteName(routeInfo.getName());
-                    }
-                    StationInfo upStation = stationInfoService.get(passengerInfo.getUpStationId());
-                    if(upStation!=null){
-                        dto.setUpStationName(upStation.getName());
-                    }
-                    StationInfo downStation = stationInfoService.get(passengerInfo.getDownStationId());
-                    if(downStation!=null){
-                        dto.setDownStationName(downStation.getName());
                     }
                     }
                 }
                 }
+
+                mapList.add(map);
             }
             }
 
 
-            pageDto.add(dto);
-        }
 
 
-        pageDto.setPageSize(page.getPageSize());
-        pageDto.setTotal(page.getTotal());
-        pageDto.setPageNum(page.getPageNum());
+            if (exportFlag) {
+                String filePath = exportXls(mapList);
+                msgResult.setData(filePath);
+            } else {
+                Map<String, Object> dataMap = PojoUtils.pageWrapper(page);
+                dataMap.put("data", mapList);
+                msgResult.setData(dataMap);
+            }
 
 
-        msgResult.setResult(true);
-        msgResult.setData(PojoUtils.pageWrapper(pageDto));
+            msgResult.setResult(true);
+        }
+        catch (Exception ex) {
+            logger.error(ex.getMessage(), ex);
+            msgResult.setResult(false);
+        }
 
 
         return msgResult;
         return msgResult;
     }
     }
 
 
 
 
+    private String exportXls(List<Map> mapList) throws IOException {
+        String downloadUrl = "";
+
+        Workbook workbook = new HSSFWorkbook();
+        Sheet sheet = workbook.createSheet();
+
+        //表头
+        Row rowTitle = sheet.createRow(0);
+
+        String[] titles = new String[]{"所属公司","车牌号","司机姓名","路线名称","账单金额(元)","支付金额(元)","支付状态","支付方式","上车站点","下车站点",
+                "购票类型","货票金额(元)","订单编号","交易流水号","创建时间","支付时间"};
+
+        for (int i=0;i<titles.length;i++) {
+            Cell cell = rowTitle.createCell(i);
+            cell.setCellValue(titles[i]);
+        }
+
+        for (int i=0;i<mapList.size();i++){
+            Map<String,Object> map = mapList.get(i);
+
+            Row row = sheet.createRow(i+1);
+
+            int colIndex = 0;
+            row.createCell(colIndex++).setCellValue(com.jpsoft.bus.modules.common.utils.StringUtils.strValue(map.get("companyName"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.bus.modules.common.utils.StringUtils.strValue(map.get("licensePlateNumber"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.bus.modules.common.utils.StringUtils.strValue(map.get("driverName"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.bus.modules.common.utils.StringUtils.strValue(map.get("routeName"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.bus.modules.common.utils.StringUtils.strValue(map.get("totalFee"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.bus.modules.common.utils.StringUtils.strValue(map.get("payFee"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.bus.modules.common.utils.StringUtils.strValue(map.get("payStatusN"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.bus.modules.common.utils.StringUtils.strValue(map.get("payNameN"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.bus.modules.common.utils.StringUtils.strValue(map.get("upStationName"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.bus.modules.common.utils.StringUtils.strValue(map.get("downStationName"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.bus.modules.common.utils.StringUtils.strValue(map.get("ticketTypeN"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.bus.modules.common.utils.StringUtils.strValue(map.get("goodsTicket"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.bus.modules.common.utils.StringUtils.strValue(map.get("outOrderNo"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.bus.modules.common.utils.StringUtils.strValue(map.get("transactionId"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.bus.modules.common.utils.StringUtils.strValue(map.get("createTime"),""));
+            row.createCell(colIndex++).setCellValue(com.jpsoft.bus.modules.common.utils.StringUtils.strValue(map.get("payTime"),""));
+
+        }
+
+        ByteArrayOutputStream output = new ByteArrayOutputStream();
+
+        try {
+            workbook.write(output);
+
+            byte[] buffer = output.toByteArray();
+            ByteArrayInputStream input = new ByteArrayInputStream(buffer);
+
+            downloadUrl = OSSUtil.upload(ossConfig,"orderInfo","订单管理列表.xls",input);
+        }
+        catch (Exception ex){
+            logger.error(ex.getMessage(),ex);
+        }
+
+        return downloadUrl;
+    }
+
+
     @ApiOperation(value = "修改订单状态")
     @ApiOperation(value = "修改订单状态")
     @PostMapping("updateOrder")
     @PostMapping("updateOrder")
     public MessageResult<Boolean> updateOrder(String id, Integer payStatus, @RequestAttribute String subject) {
     public MessageResult<Boolean> updateOrder(String id, Integer payStatus, @RequestAttribute String subject) {