Forráskód Böngészése

在小程序端显示剩余车位数量

xlq 2 napja
szülő
commit
8f82cb05c6

+ 5 - 0
src/main/java/com/qmrb/system/pojo/vo/BarnRecordVO.java

@@ -29,6 +29,11 @@ public class BarnRecordVO {
     private Long carParkId;
     private String carParkName;
     /**
+     * 剩余车位数
+     */
+    @Schema(description = "剩余车位数",type="String")
+    private String unUsedParkingSpaceNumber;
+    /**
      * 车辆进入时间
      */
 	@Schema(description = "车辆进入时间",type="Date")

+ 63 - 56
src/main/java/com/qmrb/system/service/impl/BarnRecordServiceImpl.java

@@ -8,6 +8,7 @@ import cn.hutool.core.lang.Assert;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmrb.system.converter.BarnRecordConverter;
@@ -56,11 +57,11 @@ public class BarnRecordServiceImpl extends ServiceImpl<BarnRecordMapper, BarnRec
 
     @Autowired
     private ICarParkService carParkService;
-    
+
     @Autowired
     private ICarParkStoredCardService parkStoredCardService;
-    
-    
+
+
     @Autowired
     private ICarParkChargingRulesService carParkChargingRulesService;
 
@@ -76,6 +77,8 @@ public class BarnRecordServiceImpl extends ServiceImpl<BarnRecordMapper, BarnRec
     private CouponMapper couponMapper;
     @Autowired
     private IContractPlaceNumberRelService contractPlaceNumberRelService;
+    @Autowired
+    private IBarninRecordService barninRecordService;
 
 
     /**
@@ -123,10 +126,16 @@ public class BarnRecordServiceImpl extends ServiceImpl<BarnRecordMapper, BarnRec
         ArrayList<BarnRecordVO> barnRecords = new ArrayList<>();
         for (BarnRecordVO record : pageResult.getRecords()) {
             if (record.getCarParkId() != null && map.keySet().contains(record.getCarParkId())) {
+                // 输入停车场名字
                 record.setCarParkName(map.get(record.getCarParkId()));
+                // 计算剩余车位数
+                Integer parkingSpaceNumber = carParkService.getById(record.getCarParkId()).getParkingSpaceNumber();//车位数
+                int size = barninRecordService.list(new LambdaUpdateWrapper<BarninRecord>().eq(BarninRecord::getCarParkId, record.getCarParkId())).size();//入场车辆数
+                Integer unUsedParkingSpaceNumber = parkingSpaceNumber - size;
+                record.setUnUsedParkingSpaceNumber(String.valueOf(unUsedParkingSpaceNumber));
             }
 
-            if(record.getBillingStartTime() == null){
+            if (record.getBillingStartTime() == null) {
                 BarnRecordForm form = new BarnRecordForm();
                 form.setInTime(record.getInTime());
                 form.setCarNumber(record.getCarNumber());
@@ -140,25 +149,25 @@ public class BarnRecordServiceImpl extends ServiceImpl<BarnRecordMapper, BarnRec
             LocalDateTime inDateTime = instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
             // 查询月卡,
             List<CarParkStoredCard> storedCards = parkStoredCardService.list(new LambdaQueryWrapper<CarParkStoredCard>().eq(CarParkStoredCard::getPlateNumber, record.getCarNumber())
-                    .eq(CarParkStoredCard::getStatus,1).le(CarParkStoredCard::getStartTime, inDateTime)
+                    .eq(CarParkStoredCard::getStatus, 1).le(CarParkStoredCard::getStartTime, inDateTime)
                     .orderByDesc(CarParkStoredCard::getEndTime));
-            if(CollectionUtil.isNotEmpty(storedCards)){
+            if (CollectionUtil.isNotEmpty(storedCards)) {
                 CarParkStoredCard storedCard = storedCards.get(0);
-                if(record.getOutTime() != null){
+                if (record.getOutTime() != null) {
                     // 将 Date 转换为 Instant
                     Instant instant2 = record.getOutTime().toInstant();
 
                     // 将 Instant 转换为 LocalDateTime(假设使用系统默认时区)
                     LocalDateTime outDateTime = instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
-                    if(outDateTime.isAfter(storedCard.getStartTime())){
+                    if (outDateTime.isAfter(storedCard.getStartTime())) {
                         record.setCardEndTime(storedCard.getEndTime());
                     }
-                }else if(record.getOutTime() == null && LocalDateTime.now().isAfter(storedCard.getStartTime())){
+                } else if (record.getOutTime() == null && LocalDateTime.now().isAfter(storedCard.getStartTime())) {
                     record.setCardEndTime(storedCard.getEndTime());
                 }
-                
+
             }
-            
+
             // 计算计费时长
             if (record.getOutTime() != null) {
                 record.setParkingTime(calculateTimeDifference(record.getBillingStartTime(), record.getOutTime()));
@@ -166,16 +175,16 @@ public class BarnRecordServiceImpl extends ServiceImpl<BarnRecordMapper, BarnRec
                 record.setParkingTime(calculateTimeDifference(record.getBillingStartTime(), new Date()));
                 // 查询优惠券
                 List<Coupon> coupons = couponMapper.selectList(new LambdaQueryWrapper<Coupon>().eq(Coupon::getGoodsId, record.getId()));
-                log.info("查询优惠券:{}",coupons.size());
-                if(CollectionUtil.isNotEmpty(coupons)){
+                log.info("查询优惠券:{}", coupons.size());
+                if (CollectionUtil.isNotEmpty(coupons)) {
                     Coupon coupon = coupons.get(0);
                     // 1 扫码抵用金额 2扫码抵用时长
-                    if(1 == coupon.getCouponType()){
+                    if (1 == coupon.getCouponType()) {
                         record.setDiscountAmount(coupon.getDenomination());
-                    }else if(2 == coupon.getCouponType()){
+                    } else if (2 == coupon.getCouponType()) {
                         record.setDiscountMinute(coupon.getDenomination());
                     }
-                }else{
+                } else {
                     // // 判断是否否存在包租协议
                     // Map<String,Object> denominationMap = contractPlaceNumberRelService.getDenomination(record.getId());
                     // if(CollectionUtil.isNotEmpty(denominationMap)){
@@ -187,32 +196,31 @@ public class BarnRecordServiceImpl extends ServiceImpl<BarnRecordMapper, BarnRec
                 }
             }
 
-            if(queryParams.getIsMonthlyCardMode() != null){
+            if (queryParams.getIsMonthlyCardMode() != null) {
                 // record.setPendingAmount(carParkChargingRulesService.calcuExpenses(record.getId(),record.getCarNumber(),queryParams.getIsMonthlyCardMode()));
-                record.setPendingAmountWithCoupon(carParkChargingRulesService.calcuExpensesWithCoupon(record.getId(),record.getCarNumber(),queryParams.getIsMonthlyCardMode()));
-            }else{
+                record.setPendingAmountWithCoupon(carParkChargingRulesService.calcuExpensesWithCoupon(record.getId(), record.getCarNumber(), queryParams.getIsMonthlyCardMode()));
+            } else {
                 // record.setPendingAmount(carParkChargingRulesService.calcuExpenses(record.getId(),record.getCarNumber(),false));
-                record.setPendingAmountWithCoupon(carParkChargingRulesService.calcuExpensesWithCoupon(record.getId(),record.getCarNumber(),false));
+                record.setPendingAmountWithCoupon(carParkChargingRulesService.calcuExpensesWithCoupon(record.getId(), record.getCarNumber(), false));
             }
-            if(record.getReceivedAmount() == null){
+            if (record.getReceivedAmount() == null) {
                 record.setReceivedAmount(BigDecimal.ZERO);
             }
-            if(record.getPendingAmountWithCoupon() != null){
+            if (record.getPendingAmountWithCoupon() != null) {
                 record.setBillingAmount(record.getReceivedAmount().add(record.getPendingAmountWithCoupon()));
-            }else{
+            } else {
                 record.setBillingAmount(record.getReceivedAmount());
             }
-            
-            
-            
-            if(queryParams.getIsMonthlyCardMode() != null && queryParams.getIsMonthlyCardMode()){
-                if(record.getPendingAmount().compareTo(BigDecimal.ZERO) > 0){
+
+
+            if (queryParams.getIsMonthlyCardMode() != null && queryParams.getIsMonthlyCardMode()) {
+                if (record.getPendingAmount().compareTo(BigDecimal.ZERO) > 0) {
                     barnRecords.add(record);
                 }
-            }else{
+            } else {
                 barnRecords.add(record);
             }
-            
+
         }
         pageResult.setRecords(barnRecords);
         return pageResult;
@@ -263,16 +271,16 @@ public class BarnRecordServiceImpl extends ServiceImpl<BarnRecordMapper, BarnRec
      * @return
      */
     @Override
-    public BarnRecordForm getCarParkUseLogOrder(Long id,Boolean isMonthlyCardMode) {
+    public BarnRecordForm getCarParkUseLogOrder(Long id, Boolean isMonthlyCardMode) {
         // 获取entity
         BarnRecord entity = this.getById(id);
         Assert.isTrue(entity != null, "岗亭端停车记录不存在");
 
         // 实体转换
         BarnRecordForm form = converter.entity2Form(entity);
-        
-        
-        if(form.getBillingStartTime() == null){
+
+
+        if (form.getBillingStartTime() == null) {
             Date billingStartTime = parkStoredCardService.getBillingStartTime(form);
             form.setBillingStartTime(billingStartTime);
         }
@@ -283,16 +291,16 @@ public class BarnRecordServiceImpl extends ServiceImpl<BarnRecordMapper, BarnRec
             form.setParkingTime(calculateTimeDifference(form.getBillingStartTime(), new Date()));
             // 查询优惠券
             List<Coupon> coupons = couponMapper.selectList(new LambdaQueryWrapper<Coupon>().eq(Coupon::getGoodsId, form.getId()));
-            log.info("查询优惠券:{}",coupons.size());
-            if(CollectionUtil.isNotEmpty(coupons)){
+            log.info("查询优惠券:{}", coupons.size());
+            if (CollectionUtil.isNotEmpty(coupons)) {
                 Coupon coupon = coupons.get(0);
                 // 1 扫码抵用金额 2扫码抵用时长
-                if(1 == coupon.getCouponType()){
+                if (1 == coupon.getCouponType()) {
                     form.setDiscountAmount(coupon.getDenomination());
-                }else if(2 == coupon.getCouponType()){
+                } else if (2 == coupon.getCouponType()) {
                     form.setDiscountMinute(coupon.getDenomination());
                 }
-            }else{
+            } else {
                 // // 判断是否否存在包租协议
                 // Map<String,Object> denominationMap = contractPlaceNumberRelService.getDenomination(form.getId());
                 // if(CollectionUtil.isNotEmpty(denominationMap)){
@@ -303,7 +311,6 @@ public class BarnRecordServiceImpl extends ServiceImpl<BarnRecordMapper, BarnRec
                 // }
             }
         }
-        
 
 
         List<CarPark> list = carParkService.list();
@@ -317,19 +324,19 @@ public class BarnRecordServiceImpl extends ServiceImpl<BarnRecordMapper, BarnRec
             form.setCarParkName(map.get(form.getCarParkId()));
         }
 
-        if(form.getReceivedAmount() == null){
+        if (form.getReceivedAmount() == null) {
             form.setReceivedAmount(BigDecimal.ZERO);
         }
         // 计费
         // form.setPendingAmount(carParkChargingRulesService.calcuExpenses(form.getId(),form.getCarNumber(),isMonthlyCardMode));//待收金额
-        form.setPendingAmountWithCoupon(carParkChargingRulesService.calcuExpensesWithCoupon(form.getId(),form.getCarNumber(),isMonthlyCardMode));//待收金额
-        if(form.getPendingAmountWithCoupon() != null){
-            form.setBillingAmount(form.getReceivedAmount().add(form.getPendingAmountWithCoupon()));//计费金额
-        }else{
-            form.setBillingAmount(form.getReceivedAmount());//计费金额
+        form.setPendingAmountWithCoupon(carParkChargingRulesService.calcuExpensesWithCoupon(form.getId(), form.getCarNumber(), isMonthlyCardMode));// 待收金额
+        if (form.getPendingAmountWithCoupon() != null) {
+            form.setBillingAmount(form.getReceivedAmount().add(form.getPendingAmountWithCoupon()));// 计费金额
+        } else {
+            form.setBillingAmount(form.getReceivedAmount());// 计费金额
         }
 
-        
+
         return form;
     }
 
@@ -351,7 +358,7 @@ public class BarnRecordServiceImpl extends ServiceImpl<BarnRecordMapper, BarnRec
                 barnRecord.setId(equalList.get(0).getId());
                 // 如果存在,则更新出场时间
                 updateList.add(barnRecord);
-            }else{
+            } else {
                 // 如果不存在,则新增
                 barnRecord.setId(null);
                 saveList.add(barnRecord);
@@ -364,12 +371,13 @@ public class BarnRecordServiceImpl extends ServiceImpl<BarnRecordMapper, BarnRec
 
     /**
      * 根据订单id查找停车记录
+     *
      * @param orderId
      * @return
      */
     @Override
     public BarnRecordForm chargingByBarnId(Long orderId) {
-        if(orderId == null){
+        if (orderId == null) {
             return null;
         }
         BarnRecordForm barnRecordForm = baseMapper.chargingByBarnId(orderId);
@@ -384,17 +392,16 @@ public class BarnRecordServiceImpl extends ServiceImpl<BarnRecordMapper, BarnRec
     @Override
     public boolean takeCar(Long id, BarnRecordForm form) throws MQBrokerException, RemotingException, UnsupportedEncodingException, InterruptedException, MQClientException {
         HashMap<String, Object> paramsMap = new HashMap<>();
-        paramsMap.put("channelId",form.getBarnId());
-        paramsMap.put("carNumber",form.getCarNumber());
+        paramsMap.put("channelId", form.getBarnId());
+        paramsMap.put("carNumber", form.getCarNumber());
         // 发送取车指令
-        pickCarProducer.send(topic,tags, JSONUtil.toJsonStr(paramsMap));
-        form.setEmergencyFlag("1");//应急取车标志
+        pickCarProducer.send(topic, tags, JSONUtil.toJsonStr(paramsMap));
+        form.setEmergencyFlag("1");// 应急取车标志
         boolean result = updateForm(id, form);
         return result;
     }
 
 
-
     /**
      * 计算两个时间差(年,月,星期,日,时,分,秒)
      *
@@ -430,8 +437,8 @@ public class BarnRecordServiceImpl extends ServiceImpl<BarnRecordMapper, BarnRec
         long seconds = tempDateTime.until(toDateTime, ChronoUnit.SECONDS);
 
         long between = DateUtil.between(endDate, startDate, DateUnit.DAY);
-        String res =  (between > 0   ? ( between + "天") : "") + (hours > 0 ? (hours + "小时") : "") + (minutes > 0 ? (minutes + "分") : "");
-        
+        String res = (between > 0 ? (between + "天") : "") + (hours > 0 ? (hours + "小时") : "") + (minutes > 0 ? (minutes + "分") : "");
+
         return res;
 
     }

+ 9 - 1
src/main/java/com/qmrb/system/service/impl/ContractServiceImpl.java

@@ -137,7 +137,15 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> i
         // 修改账户或密码,更新用户表数据
         Contract contract = this.getById(id);
         SysUser user = userService.getOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getContractId, id));
-
+        // 防止新增协议未输入账号密码
+        if (StringUtils.isBlank(contract.getUsername()) || StringUtils.isBlank(contract.getPassword())){
+            contract.setUsername(form.getUsername());
+            contract.setPassword(form.getPassword());
+            this.updateById(contract);
+            user.setUsername(form.getUsername());
+            user.setPassword(form.getPassword());
+            userService.updateById(user);
+        }
         Boolean changeFlag = false;
         // 校验账户
         if (!contract.getUsername().equals(form.getUsername())) {