| | |
| | | package com.xiaopeng.map.controller; |
| | | |
| | | |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import com.xiaopeng.api.dto.operation.PointAddDto; |
| | | import com.xiaopeng.api.dto.operation.PointUpdateDto; |
| | | import com.xiaopeng.api.dto.operation.XpPointEnableDisableDto; |
| | |
| | | import com.xiaopeng.api.query.operation.PointListQuery; |
| | | import com.xiaopeng.api.query.operation.PointPageListListQuery; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.utils.WebUtils; |
| | | import com.xiaopeng.common.core.web.controller.BaseController; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | import com.xiaopeng.common.security.service.TokenService; |
| | | import com.xiaopeng.map.exportExcel.XpPointExportExcel; |
| | | import com.xiaopeng.api.dto.map.XpPointExportExcelQuery; |
| | | import io.seata.spring.annotation.GlobalTransactional; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.net.URLEncoder; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | |
| | | @ApiOperation(value = "点位管理分页列表", response = XpPoint.class) |
| | | @PostMapping("/pageList") |
| | | public R<PageInfo<XpPoint>> pageList(@RequestBody PointPageListListQuery query) { |
| | | |
| | | return xpPointClient.pageList(query); |
| | | } |
| | | @ApiOperation(value = "点位导出") |
| | | @PostMapping(value = "/exportExcel") |
| | | public void exportExcel(@RequestBody XpPointExportExcelQuery query) { |
| | | List<XpPoint> exportList = xpPointClient.getByIds(query).getData(); |
| | | List<XpPointExportExcel> xpPointExportExcels = new ArrayList<>(); |
| | | for (XpPoint xpPoint : exportList) { |
| | | XpPointExportExcel xpPointExportExcel = new XpPointExportExcel(); |
| | | xpPointExportExcel.setPointNumber(xpPoint.getPointNumber()); |
| | | xpPointExportExcel.setPointName(xpPoint.getPointName()); |
| | | xpPointExportExcel.setStatus(xpPoint.getOperationStatus()); |
| | | xpPointExportExcel.setParkingTimeLimit(xpPoint.getParkingTimeLimit()+"分钟"); |
| | | xpPointExportExcel.setPointLon(xpPoint.getPointLon()); |
| | | xpPointExportExcel.setPointLat(xpPoint.getPointLat()); |
| | | xpPointExportExcel.setCreateBy(xpPoint.getCreateBy()); |
| | | xpPointExportExcel.setCreateTime(xpPoint.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | xpPointExportExcels.add(xpPointExportExcel); |
| | | } |
| | | //1.获取excel模板 |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), XpPointExportExcel.class, xpPointExportExcels); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | ServletOutputStream outputStream = null; |
| | | try { |
| | | String fileName = URLEncoder.encode("点位列表.csv", "utf-8"); |
| | | response.setHeader("Content-dispodition", "attachment;filename=" + fileName); |
| | | outputStream = response.getOutputStream(); |
| | | workbook.write(outputStream); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | | outputStream.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | @ApiOperation(value = "点位管理列表", response = XpPoint.class) |
| | | @PostMapping("/list") |
| | | public R<List<XpPoint>> list(@RequestBody PointListQuery query) { |