| | |
| | | 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.feignClient.operation.XpPointClient; |
| | | import com.xiaopeng.api.model.operation.XpElectronicFence; |
| | | import com.xiaopeng.api.model.operation.XpElectronicFenceArea; |
| | | import com.xiaopeng.api.model.operation.XpPoint; |
| | | 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 com.xiaopeng.map.service.XpElectronicFenceAreaService; |
| | | import com.xiaopeng.map.service.XpElectronicFenceService; |
| | | import com.xiaopeng.map.service.XpPointService; |
| | | 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.beans.BeanUtils; |
| | | 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; |
| | | |
| | | |
| | | @Slf4j |
| | | @RestController |
| | |
| | | public class XpPointManagementController extends BaseController { |
| | | |
| | | @Resource |
| | | private XpPointClient xpPointClient; |
| | | |
| | | private XpPointService xpPointService; |
| | | @Resource |
| | | private TokenService tokenService; |
| | | private XpElectronicFenceAreaService xpElectronicFenceAreaService; |
| | | @Resource |
| | | private XpElectronicFenceService xpElectronicFenceService; |
| | | |
| | | |
| | | @ApiOperation(value = "获取所有运营中的区域", response = XpElectronicFenceArea.class) |
| | | @PostMapping("/listElectronicFenceArea") |
| | | public R<List<XpElectronicFenceArea>> listElectronicFenceArea() { |
| | | R<List<XpElectronicFenceArea>> listR = xpPointClient.listElectronicFenceArea(); |
| | | |
| | | |
| | | return listR; |
| | | } |
| | | @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); |
| | | // 获取所有启用的电子围栏 |
| | | List<XpElectronicFence> electronicFences = xpElectronicFenceService.lambdaQuery().eq(XpElectronicFence::getStatus, 2).list(); |
| | | List<Long> electronicFenceIds = electronicFences.stream().map(XpElectronicFence::getId).collect(Collectors.toList()); |
| | | if (electronicFenceIds.isEmpty()) { |
| | | return R.ok(new ArrayList<XpElectronicFenceArea>()); |
| | | } |
| | | //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(); |
| | | } |
| | | } |
| | | |
| | | // 获取电子围栏下启用的运营区域 |
| | | List<XpElectronicFenceArea> electronicFenceAreaList = xpElectronicFenceAreaService.lambdaQuery().in(XpElectronicFenceArea::getElectronicId, electronicFenceIds) |
| | | .eq(XpElectronicFenceArea::getAreaStatus, 1).list(); |
| | | return R.ok(electronicFenceAreaList); |
| | | } |
| | | |
| | | @ApiOperation(value = "点位管理列表", response = XpPoint.class) |
| | | @PostMapping("/list") |
| | | public R<List<XpPoint>> list(@RequestBody PointListQuery query) { |
| | | if (StringUtils.hasLength(query.getOperationStatus())){ |
| | | List<Integer> operationStatusIds = Arrays.stream(query.getOperationStatus().split(",")).map(Integer::parseInt).collect(Collectors.toList()); |
| | | query.setOperationStatusIds(operationStatusIds); |
| | | } |
| | | return xpPointClient.list( query); |
| | | List<XpPoint> pageList = xpPointService.listAll(query); |
| | | return R.ok(pageList); |
| | | } |
| | | |
| | | @ApiOperation(value = "点位管理分页列表", response = XpPoint.class) |
| | | @PostMapping("/pageList") |
| | | public R<PageInfo<XpPoint>> pageList(@RequestBody PointPageListListQuery query) { |
| | | PageInfo<XpPoint> pageList = xpPointService.pageList(query); |
| | | return R.ok(pageList); |
| | | } |
| | | |
| | | @PostMapping("/getByIds") |
| | | public R<List<XpPoint>> getByIds(@RequestBody XpPointExportExcelQuery query) { |
| | | List<XpPoint> list = xpPointService.lambdaQuery().in(XpPoint::getId, query.getPointIds()).list(); |
| | | return R.ok(list); |
| | | } |
| | | |
| | | /** |
| | | * 新增点位 |
| | | */ |
| | | |
| | | @PostMapping("/add") |
| | | @ResponseBody |
| | | @ApiOperation(value = "新增点位") |
| | | // @Transactional |
| | | // @ShardingSphereTransactionType(TransactionType.BASE) |
| | | public R add(@Validated @RequestBody PointAddDto pointAddDto) { |
| | | xpPointClient.add(pointAddDto); |
| | | public R add(@Validated @RequestBody PointAddDto pointAddDto) { |
| | | XpPoint xpPoint = new XpPoint(); |
| | | BeanUtils.copyProperties(pointAddDto, xpPoint); |
| | | xpPointService.save(xpPoint); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除点位 |
| | | */ |
| | | @GetMapping("/delete") |
| | | @ResponseBody |
| | | @ApiOperation(value = "删除点位") |
| | | // @Transactional |
| | | // @ShardingSphereTransactionType(TransactionType.BASE) |
| | | public R deletePoint(@RequestParam("ids") String ids) { |
| | | xpPointService.removeBatchByIds(Arrays.stream(ids.split(",")).map(Long::parseLong).collect(Collectors.toList())); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 编辑点位 |
| | | */ |
| | |
| | | @ApiOperation(value = "编辑点位") |
| | | // @Transactional |
| | | // @ShardingSphereTransactionType(TransactionType.BASE) |
| | | public R edit(@Validated@RequestBody PointUpdateDto pointAddDto) { |
| | | xpPointClient.edit(pointAddDto); |
| | | public R edit(@Validated @RequestBody PointUpdateDto pointAddDto) { |
| | | XpPoint xpPoint = new XpPoint(); |
| | | BeanUtils.copyProperties(pointAddDto, xpPoint); |
| | | xpPointService.updateById(xpPoint); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除点位 |
| | | * 点位详情 |
| | | */ |
| | | @GetMapping("/deletePoint") |
| | | @ApiOperation(value = "删除点位") |
| | | // @Transactional |
| | | // @ShardingSphereTransactionType(TransactionType.BASE) |
| | | public R deletePoint(@RequestParam("ids") String ids) { |
| | | xpPointClient.deletePoint(ids); |
| | | return R.ok(); |
| | | } |
| | | /** |
| | | * 编辑点位 |
| | | */ |
| | | @GetMapping("/queryById") |
| | | @ResponseBody |
| | | @GetMapping("/api/v1/point/queryById") |
| | | @ApiOperation(value = "点位详情") |
| | | public R queryById(@RequestParam Long id) { |
| | | return xpPointClient.queryById( id); |
| | | public R<XpPoint> queryById(@RequestParam Long id) { |
| | | return R.ok(xpPointService.getById(id)); |
| | | } |
| | | |
| | | /** |
| | | * 启用/禁用 |
| | | */ |
| | | @PostMapping("/enableDisable") |
| | | @ResponseBody |
| | | @ApiOperation(value = "启用/禁用") |
| | | // @Transactional |
| | | // @ShardingSphereTransactionType(TransactionType.BASE) |
| | | public R enableDisable(@RequestBody XpPointEnableDisableDto dto) { |
| | | return xpPointClient.enableDisable(dto); |
| | | XpPoint xpPoint = xpPointService.getById(dto.getId()); |
| | | xpPoint.setOperationStatus(dto.getOperationStatus()); |
| | | xpPoint.setElectronicAreaId(null); |
| | | xpPointService.updateById(xpPoint); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | } |