From c05a14bba4b86d83918d7cdc01635785bf5694c2 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期二, 03 六月 2025 00:26:08 +0800 Subject: [PATCH] 拆分mongodb查询服务 --- ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TParkingRecordController.java | 155 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 144 insertions(+), 11 deletions(-) diff --git a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TParkingRecordController.java b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TParkingRecordController.java index 3ead497..54d1169 100644 --- a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TParkingRecordController.java +++ b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TParkingRecordController.java @@ -5,6 +5,9 @@ import cn.afterturn.easypoi.excel.entity.ExportParams; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ruoyi.chargingPile.api.dto.GetSiteListDTO; +import com.ruoyi.chargingPile.api.feignClient.PartnerClient; +import com.ruoyi.chargingPile.api.feignClient.SiteClient; import com.ruoyi.chargingPile.api.model.TParkingLot; import com.ruoyi.chargingPile.api.model.TParkingRecord; import com.ruoyi.chargingPile.api.query.ParkingRecordQuery; @@ -22,9 +25,14 @@ import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.enums.BusinessType; import com.ruoyi.common.log.enums.OperatorType; +import com.ruoyi.common.security.service.TokenService; +import com.ruoyi.common.security.annotation.Logical; +import com.ruoyi.common.security.annotation.RequiresPermissions; import com.ruoyi.order.api.query.TOrderInvoiceQuery; import com.ruoyi.order.api.vo.TCharingUserEquimentVO; import com.ruoyi.order.api.vo.TOrderInvoiceVO; +import com.ruoyi.system.api.domain.SysUser; +import com.ruoyi.system.api.feignClient.SysUserClient; import io.swagger.annotations.ApiOperation; import org.apache.poi.ss.usermodel.Workbook; import org.springframework.beans.BeanUtils; @@ -37,6 +45,7 @@ import java.math.BigDecimal; import java.net.URLEncoder; import java.time.LocalDate; +import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.HashMap; @@ -59,28 +68,97 @@ private TParkingRecordService parkingRecordService; @Resource private TParkingLotService parkingLotService; + @Resource + private SiteClient siteClient; + @Resource + private TokenService tokenService; + @Resource + private PartnerClient partnerClient; + @Resource + private SysUserClient sysUserClient; + @RequiresPermissions(value = {"/parkingRecord"}, logical = Logical.OR) @ApiOperation(tags = {"后台-订单管理-停车记录"},value = "列表") @PostMapping(value = "/page") public R<Page<TParkingRecord>> page(@RequestBody ParkingRecordPageQuery query) { + Long userid = tokenService.getLoginUser().getUserid(); + SysUser sysUser = sysUserClient.getSysUser(tokenService.getLoginUser().getUserid()).getData(); + Integer roleType = sysUser.getRoleType(); + List<Integer> siteIds = new ArrayList<>(); + + List<GetSiteListDTO> data = siteClient.getSiteListByUserId(userid).getData(); + for (GetSiteListDTO datum : data) { + siteIds.add(datum.getId()); + } + if (siteIds.isEmpty()){ + siteIds.add(-1); + }else{ + if (roleType == 2){ + List<Integer> integers = new ArrayList<>(); + for (Integer siteId : siteIds) { + // 校验有没有这个站点的权限 + List<Boolean> t1= partnerClient.parkingRecordListMenu(sysUser.getObjectId(),siteId).getData(); + + Boolean b = t1.get(1); + if (b){ + integers.add(siteId); + } + } + siteIds = integers; + } + } + if (siteIds.isEmpty()){ + siteIds.add(-1); + } + List<TParkingLot> list = parkingLotService.lambdaQuery().in( TParkingLot::getSiteId, siteIds).list(); + List<Integer> ids = new ArrayList<>(); + for (TParkingLot tParkingLot : list) { + ids.add(tParkingLot.getId()); + } + + + String s1 = ""; + String s2 = ""; + if (query.getTimePeriod()!=null){ + s1 = query.getTimePeriod().split(" - ")[0]; + s2 = query.getTimePeriod().split(" - ")[1]; + } Page<TParkingRecord> page = parkingRecordService.lambdaQuery() + .in(null != ids && ids.size() > 0, TParkingRecord::getParkingLotId,ids) .like(query.getLicensePlate() != null, TParkingRecord::getLicensePlate, query.getLicensePlate()) .eq(query.getStatus() != null, TParkingRecord::getStatus, query.getStatus()) .eq(query.getOutParkingType() != null, TParkingRecord::getOutParkingType, query.getOutParkingType()) + .between(query.getTimePeriod()!=null,TParkingRecord::getInParkingTime,s1,s2) + .or() + .between(query.getTimePeriod()!=null,TParkingRecord::getOutParkingTime,s1,s2) + .orderByDesc(TParkingRecord::getCreateTime) .page(Page.of(query.getPageCurr(), query.getPageSize())); for (TParkingRecord record : page.getRecords()) { - record.setName(parkingLotService.getById(record.getParkingLotId()).getName()); + TParkingLot byId = parkingLotService.getById(record.getParkingLotId()); record.setUid(record.getId().toString()); + if (byId!=null) { + record.setParkName(byId.getName()); + if (roleType==2){ + List<Boolean> data1 = partnerClient.parkingRecordListMenu(sysUser.getObjectId(), byId.getSiteId()).getData(); + record.setAuthInfo(data1.get(0)); + record.setAuthOut(data1.get(1)); + } + } } return R.ok(page); } - + + + @RequiresPermissions(value = {"/parkingPaymentOrder"}, logical = Logical.OR) @ApiOperation(tags = {"后台-订单管理-停车记录"},value = "停车缴费订单列表") @PostMapping(value = "/pageList") public R<TParkingRecordPageInfoVO> pageList(@RequestBody ParkingRecordQuery query) { return R.ok(parkingRecordService.pageList(query)); } + + + @RequiresPermissions(value = {"/parkingPaymentOrder/export"}, logical = Logical.OR) @ApiOperation(tags = {"后台-订单管理-停车记录"},value = "导出") @PutMapping("/export") @Log(title = "【停车记录】导出停车记录", businessType = BusinessType.EXPORT,operatorType = OperatorType.MANAGE) @@ -126,18 +204,25 @@ } } } + + + + @ApiOperation(tags = {"后台-订单管理-停车记录"},value = "详情") @GetMapping(value = "/detail") public R<TParkingRecord> detail(Long id) { return R.ok(parkingRecordService.getById(id)); } - + + + @RequiresPermissions(value = {"/parkingRecord/already_appeared"}, logical = Logical.OR) @ApiOperation(tags = {"后台-订单管理-停车记录"},value = "出场") @GetMapping(value = "/out") @Log(title = "【停车记录】修改出场状态", businessType = BusinessType.UPDATE,operatorType = OperatorType.MANAGE) public R out(Long id) { TParkingRecord byId = parkingRecordService.getById(id); byId.setStatus(2); + byId.setOutParkingTime(LocalDateTime.now()); parkingRecordService.updateById(byId); return R.ok(); @@ -179,6 +264,20 @@ } + + /** + * 根据充电订单id获取数据 + * @return + */ + @PostMapping("/getParkingRecordByChargingOrderId") + public R<TParkingRecord> getParkingRecordByChargingOrderId(@RequestParam("chargingOrderId") Long chargingOrderId){ + TParkingRecord parkingRecord = parkingRecordService.getOne(new LambdaQueryWrapper<TParkingRecord>() + .eq(TParkingRecord::getChargingOrderId, chargingOrderId)); + return R.ok(parkingRecord); + } + + + /** * 添加数据 * @param parkingRecord @@ -187,20 +286,37 @@ public void addParkingRecord(@RequestBody TParkingRecord parkingRecord){ parkingRecordService.save(parkingRecord); } - + + + @RequiresPermissions(value = {"/parkingOperationAnalysis"}, logical = Logical.OR) @ResponseBody @PostMapping(value = "/parking/data") @ApiOperation(value = "统计", tags = {"管理后台-数据分析-车场运营分析"}) public R<TParkLotRecordVO> data(@RequestBody ParkingRecordQueryDto parkingRecordQueryDto){ //上方折线图 TParkLotRecordVO tParkLotRecordVO = new TParkLotRecordVO(); - + // 查询当前登陆人按钮权限 + SysUser sysUser = sysUserClient.getSysUser(tokenService.getLoginUser().getUserid()).getData(); + Integer roleType = sysUser.getRoleType(); + Long userId = tokenService.getLoginUser().getUserid(); + //如果没传siteId,获取当前登陆人所有的siteIds + List<Integer> siteIds = new ArrayList<>(); + if (userId != null){ + List<GetSiteListDTO> data2 = siteClient.getSiteListByUserId(userId).getData(); + for (GetSiteListDTO datum : data2) { + siteIds.add(datum.getId()); + } + } + if (siteIds.isEmpty()){ + siteIds.add(-1); + } + parkingRecordQueryDto.setSiteIds(siteIds); if (parkingRecordQueryDto.getDayType()==1) { List<Map<String, Object>> maps = parkingRecordService.parkingData(parkingRecordQueryDto); List<Map<String, Object>> charMap = new ArrayList<>(); - // 生成从 "00:00" 到 "23:00" 的时间数据 + // 生成从 "00:00" 到 "23:00" 的时间数据------- for (int hour = 0; hour < 24; hour++) { String time = String.format("%02d:00", hour); Map<String, Object> mapWithTimeValue = findMapWithTimeValue(maps, time); @@ -272,6 +388,9 @@ return R.ok(tParkLotRecordVO); } + + + private static Map<String, Object> findMapWithTimeValue(List<Map<String, Object>> charMap1,String timeValue) { for (Map<String, Object> map : charMap1) { if (map.containsKey("time") && map.get("time").equals(timeValue)) { @@ -280,6 +399,8 @@ } return null; // 如果没有找到,返回 null } + + private Map<String, Object> findMapWithDateValue(List<Map<String, Object>> list, String date) { for (Map<String, Object> map : list) { @@ -289,11 +410,15 @@ } return null; } + + + + @RequiresPermissions(value = {"/workbench"}, logical = Logical.OR) @ResponseBody @PostMapping(value = "/parking/work") @ApiOperation(value = "停车订单统计", tags = {"管理后台-工作台"}) public R<TParkLotRecordCountVo> work(@RequestBody ParkingRecordQueryDto parkingRecordQueryDto){ - List<TParkingRecord> list = parkingRecordService.lambdaQuery().eq(parkingRecordQueryDto.getParkingLotId() != null, TParkingRecord::getParkingLotId, parkingRecordQueryDto.getParkingLotId()) + List<TParkingRecord> list = parkingRecordService.lambdaQuery().isNotNull(TParkingRecord::getOutParkingType).eq(parkingRecordQueryDto.getParkingLotId() != null, TParkingRecord::getParkingLotId, parkingRecordQueryDto.getParkingLotId()) .ge(parkingRecordQueryDto.getStartTime()!=null,TParkingRecord::getCreateTime, parkingRecordQueryDto.getStartTime()) .le(parkingRecordQueryDto.getEndTime()!=null,TParkingRecord::getCreateTime, parkingRecordQueryDto.getEndTime().plusDays(1)).list(); int count1 = list.size(); @@ -318,15 +443,20 @@ return R.ok(tParkLotRecordCountVo); } + + + + + @RequiresPermissions(value = {"/workbench"}, logical = Logical.OR) @ResponseBody @PostMapping(value = "/parking/work1") @ApiOperation(value = "停车订单统计", tags = {"管理后台-工作台"}) public R<TParkLotRecordCountVo> work1(@RequestBody ParkingRecordQueryDto parkingRecordQueryDto){ - List<TParkingRecord> list = parkingRecordService.lambdaQuery().eq(parkingRecordQueryDto.getParkingLotId() != null, TParkingRecord::getParkingLotId, parkingRecordQueryDto.getParkingLotId()).list(); + List<TParkingRecord> list = parkingRecordService.lambdaQuery().isNotNull(TParkingRecord::getOutParkingType).eq(parkingRecordQueryDto.getParkingLotId() != null, TParkingRecord::getParkingLotId, parkingRecordQueryDto.getParkingLotId()).list(); int count1 = list.size(); //统计出list中chargingOrderId为null的数据个数 - int count2 = list.stream().filter(item -> item.getChargingOrderId() == null).collect(Collectors.toList()).size(); - int count3 = count1-count2; + int count2 = list.stream().filter(item -> item.getChargingOrderId() != null).collect(Collectors.toList()).size(); + int count3 = list.stream().filter(item -> item.getOutParkingType() == 2).collect(Collectors.toList()).size(); //计算出list中parkingDuration的总和 int count4 = 0; for (TParkingRecord tParkingRecord : list) { @@ -345,7 +475,10 @@ return R.ok(tParkLotRecordCountVo); } - + + + + @RequiresPermissions(value = {"/workbench"}, logical = Logical.OR) @ResponseBody @PostMapping(value = "/parking/income") @ApiOperation(value = "停车收入统计", tags = {"管理后台-工作台"}) -- Gitblit v1.7.1