| | |
| | | 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.apache.shardingsphere.transaction.annotation.ShardingSphereTransactionType; |
| | | import org.apache.shardingsphere.transaction.core.TransactionType; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | 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") |
| | |
| | | /** |
| | | * 新增点位 |
| | | */ |
| | | @GlobalTransactional(name = "add-point", rollbackFor = Exception.class) |
| | | |
| | | @PostMapping("/add") |
| | | @ApiOperation(value = "新增点位") |
| | | @Transactional |
| | | @ShardingSphereTransactionType(TransactionType.BASE) |
| | | public R add(@Validated @RequestBody PointAddDto pointAddDto) { |
| | | return xpPointClient.add(pointAddDto); |
| | | xpPointClient.add(pointAddDto); |
| | | return R.ok(); |
| | | } |
| | | /** |
| | | * 编辑点位 |
| | | */ |
| | | @PostMapping("/edit") |
| | | @Transactional |
| | | @ShardingSphereTransactionType(TransactionType.BASE) |
| | | @ApiOperation(value = "编辑点位") |
| | | public R edit(@Validated@RequestBody PointUpdateDto pointAddDto) { |
| | | |
| | | return xpPointClient.edit(pointAddDto); |
| | | xpPointClient.edit(pointAddDto); |
| | | return R.ok(); |
| | | } |
| | | /** |
| | | * 批量删除点位 |
| | |
| | | @GetMapping("/deletePoint") |
| | | @ResponseBody |
| | | @ApiOperation(value = "删除点位") |
| | | @Transactional |
| | | @ShardingSphereTransactionType(TransactionType.BASE) |
| | | public R deletePoint(@RequestParam("ids") String ids) { |
| | | xpPointClient.deletePoint(ids); |
| | | return R.ok(); |
| | |
| | | @PostMapping("/enableDisable") |
| | | @ResponseBody |
| | | @ApiOperation(value = "启用/禁用") |
| | | @Transactional |
| | | @ShardingSphereTransactionType(TransactionType.BASE) |
| | | public R enableDisable(@RequestBody XpPointEnableDisableDto dto) { |
| | | return xpPointClient.enableDisable(dto); |
| | | } |