Parcourir la source

停车记录批量新增接口

xlq il y a 1 mois
Parent
commit
e2fd79e918

+ 13 - 1
src/main/java/com/qmrb/system/controller/BarnRecordController.java

@@ -4,6 +4,7 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.stream.Collectors;
 
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.lang.Assert;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.qmrb.system.pojo.entity.BarnRecord;
@@ -75,7 +76,18 @@ public class BarnRecordController{
         Page<BarnRecordVO> result = barnRecordService.getPage(queryParams);        
         return PageResult.success(result);
     }
-    
+    @Operation(summary = "批量新增或者修改多条岗亭端停车记录", security = {@SecurityRequirement(name = "Authorization")})
+    @PostMapping("/saveBatchOrUpdate")
+    @Resubmit
+    public Result<?> saveOrUpdateBatch(@RequestBody @Valid List<BarnRecordForm> list) {
+        List<BarnRecordForm> result = barnRecordService.saveBatchOrUpdate(list);
+        if (CollectionUtil.isNotEmpty(result)){
+            return Result.success(result);
+        }else{
+            return Result.failed("批量新增或者修改多条岗亭端停车记录失败");
+        }
+    }
+
     @Operation(summary = "新增岗亭端停车记录", security = {@SecurityRequirement(name = "Authorization")})
     @PostMapping
     @Resubmit

+ 104 - 0
src/main/java/com/qmrb/system/controller/BarninRecordController.java

@@ -0,0 +1,104 @@
+package com.qmrb.system.controller;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import cn.hutool.core.collection.CollectionUtil;
+import com.qmrb.system.pojo.form.BarnRecordForm;
+import org.springdoc.core.annotations.ParameterObject;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.security.SecurityRequirement;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.qmrb.system.common.result.PageResult;
+import com.qmrb.system.common.result.Result;
+import com.qmrb.system.common.result.ResultCode;
+import com.qmrb.system.framework.resubmit.Resubmit;
+import com.qmrb.system.service.IBarninRecordService;
+import com.qmrb.system.pojo.form.BarninRecordForm;
+import com.qmrb.system.pojo.vo.BarninRecordVO;
+import com.qmrb.system.pojo.query.BarninRecordQuery;
+
+import cn.hutool.core.util.StrUtil;
+import org.springframework.web.bind.annotation.RestController;
+import jakarta.validation.Valid;
+import lombok.RequiredArgsConstructor;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author xue
+ * @since 2025-03-03
+ */
+@Tag(name = "停车入场记录接口")
+@RestController
+@RequestMapping("/api/v1/barnin_record")
+@RequiredArgsConstructor
+public class BarninRecordController{
+
+    private final IBarninRecordService barninRecordService;
+
+	@Operation(summary = "分页列表", security = {@SecurityRequirement(name = "Authorization")})
+    @GetMapping("/page")
+    public PageResult<BarninRecordVO> getPage(@ParameterObject BarninRecordQuery queryParams) {
+        Page<BarninRecordVO> result = barninRecordService.getPage(queryParams);
+        return PageResult.success(result);
+    }
+
+    @Operation(summary = "批量新增多条停车入场记录", security = {@SecurityRequirement(name = "Authorization")})
+    @PostMapping("/saveBatch")
+    @Resubmit
+    public Result<?> saveBatch(@RequestBody @Valid List<BarninRecordForm> list) {
+        List<BarninRecordForm> result = barninRecordService.saveBatch(list);
+        return Result.success(result);
+    }
+    
+    @Operation(summary = "新增", security = {@SecurityRequirement(name = "Authorization")})
+    @PostMapping
+    @Resubmit
+    public Result<BarninRecordForm> saveForm(@RequestBody @Valid BarninRecordForm form) {
+        BarninRecordForm result = barninRecordService.saveForm(form);
+        return Result.success(result);
+    }
+
+    @Operation(summary = "表单数据", security = {@SecurityRequirement(name = "Authorization")})
+    @GetMapping("/{id}/form")
+    public Result<BarninRecordForm> getForm(@Parameter(description = "ID") @PathVariable Long id) {
+    	BarninRecordForm formData = barninRecordService.getFormData(id);
+        return Result.success(formData);
+    }
+
+    @Operation(summary = "修改", security = {@SecurityRequirement(name = "Authorization")})
+    @PutMapping(value = "/{id}")
+    public Result<?> updateForm(@Parameter(description = "ID") @PathVariable Long id, @RequestBody @Validated BarninRecordForm form) {
+        boolean result = barninRecordService.updateForm(id,form);
+        return Result.judge(result);
+    }
+
+    @Operation(summary = "删除", security = {@SecurityRequirement(name = "Authorization")})
+    @DeleteMapping("/{ids}")
+    public Result<?> deleteUsers( @Parameter(description = "ID,多个以英文逗号(,)分割") @PathVariable String ids) {
+    	if(StrUtil.isBlank(ids)) {
+    		 return Result.failed(ResultCode.PARAM_ERROR, "删除的数据为空");
+    	}
+        // 逻辑删除
+        List<Long> idList = Arrays.asList(ids.split(",")).stream()
+                .map(idStr -> Long.parseLong(idStr)).collect(Collectors.toList());
+        boolean result = barninRecordService.removeByIds(idList);
+        return Result.judge(result);
+    }
+
+}

+ 29 - 0
src/main/java/com/qmrb/system/converter/BarninRecordConverter.java

@@ -0,0 +1,29 @@
+package com.qmrb.system.converter;
+
+import org.mapstruct.InheritInverseConfiguration;
+import org.mapstruct.Mapper;
+import org.mapstruct.ReportingPolicy;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.qmrb.system.pojo.entity.BarninRecord;
+import com.qmrb.system.pojo.form.BarninRecordForm;
+import com.qmrb.system.pojo.vo.BarninRecordVO;
+
+/**
+ * 数据项对象转换器
+ *
+ * @author xue
+ * @since 2025-03-03
+ */
+@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
+public interface BarninRecordConverter {
+
+    Page<BarninRecordVO> entity2Page(Page<BarninRecord> page);
+
+    BarninRecordForm entity2Form(BarninRecord entity);
+
+    @InheritInverseConfiguration(name="entity2Form")
+    BarninRecord form2Entity(BarninRecordForm form);
+    
+    
+}

+ 18 - 0
src/main/java/com/qmrb/system/mapper/BarninRecordMapper.java

@@ -0,0 +1,18 @@
+package com.qmrb.system.mapper;
+
+import com.qmrb.system.pojo.entity.BarninRecord;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author xue
+ * @since 2025-03-03
+ */
+@Mapper
+public interface BarninRecordMapper extends BaseMapper<BarninRecord> {
+
+}

+ 64 - 0
src/main/java/com/qmrb/system/pojo/entity/BarninRecord.java

@@ -0,0 +1,64 @@
+package com.qmrb.system.pojo.entity;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.qmrb.system.common.base.BaseEntity;
+import java.util.Date;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableField;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author xue
+ * @since 2025-03-03
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@TableName("barnin_record")
+public class BarninRecord extends BaseEntity {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    @TableField("barn_id")
+    private Long barnId;
+
+    @TableField("place_no")
+    private String placeNo;
+
+    @TableField("car_number")
+    private String carNumber;
+
+    @TableField("in_time")
+    private Date inTime;
+
+    @TableField("in_image")
+    private String inImage;
+
+    @TableField("in_channel_id")
+    private Integer inChannelId;
+
+    @TableField("out_time")
+    private Date outTime;
+
+    @TableField("out_channel_id")
+    private Integer outChannelId;
+
+    @TableField("status")
+    private Integer status;
+
+    /**
+     * 停车场id
+     */
+    @TableField("car_park_id")
+    private Long carParkId;
+
+
+}

+ 34 - 0
src/main/java/com/qmrb/system/pojo/form/BarninRecordForm.java

@@ -0,0 +1,34 @@
+package com.qmrb.system.pojo.form;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+/**
+ * <p>
+ * 表单
+ * </p>
+ *
+ * @author xue
+ * @since 2025-03-03
+ */
+@Data
+public class BarninRecordForm {
+
+    private Long id;
+    private Long barnId;
+    private String placeNo;
+    private String carNumber;
+    private Date inTime;
+    private String inImage;
+    private Integer inChannelId;
+    private Date outTime;
+    private Integer outChannelId;
+    private Integer status;
+    /**
+     * 停车场id
+     */
+	@Schema(description = "停车场id",type="Long")
+    private Long carParkId;
+
+
+}

+ 40 - 0
src/main/java/com/qmrb/system/pojo/query/BarninRecordQuery.java

@@ -0,0 +1,40 @@
+package com.qmrb.system.pojo.query;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import com.qmrb.system.common.base.BasePageQuery;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * <p>
+ * 查询对象
+ * </p>
+ *
+ * @author xue
+ * @since 2025-03-03
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class BarninRecordQuery extends BasePageQuery{
+
+ 	@Schema(description="关键字")
+    private String keywords;
+
+    private Long id;
+    private Long barnId;
+    private String placeNo;
+    private String carNumber;
+    private Date inTime;
+    private String inImage;
+    private Integer inChannelId;
+    private Date outTime;
+    private Integer outChannelId;
+    private Integer status;
+    /**
+     * 停车场id
+     */
+	@Schema(description = "停车场id",type="Long")
+    private Long carParkId;
+
+
+}

+ 35 - 0
src/main/java/com/qmrb/system/pojo/vo/BarninRecordVO.java

@@ -0,0 +1,35 @@
+package com.qmrb.system.pojo.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+/**
+ * <p>
+ * 视图对象
+ * </p>
+ *
+ * @author xue
+ * @since 2025-03-03
+ */
+@Data
+public class BarninRecordVO {
+
+    private Long id;
+    private Long barnId;
+    private String placeNo;
+    private String carNumber;
+    private Date inTime;
+    private String inImage;
+    private Integer inChannelId;
+    private Date outTime;
+    private Integer outChannelId;
+    private Integer status;
+    /**
+     * 停车场id
+     */
+	@Schema(description = "停车场id",type="Long")
+    private Long carParkId;
+
+
+
+}

+ 3 - 1
src/main/java/com/qmrb/system/service/IBarnRecordService.java

@@ -7,7 +7,6 @@ import com.qmrb.system.pojo.entity.BarnRecord;
 import com.qmrb.system.pojo.form.BarnRecordForm;
 import com.qmrb.system.pojo.vo.BarnRecordVO;
 import com.qmrb.system.pojo.query.BarnRecordQuery;
-import com.qmrb.system.pojo.vo.Option;
 import com.baomidou.mybatisplus.extension.service.IService;
 import jakarta.validation.Valid;
 
@@ -39,4 +38,7 @@ public interface IBarnRecordService extends IService<BarnRecord> {
 	public BarnRecordForm getFormData(Long id);
 
 	BarnRecordForm getCarParkUseLogOrder(Long id);
+
+
+	List<BarnRecordForm> saveBatchOrUpdate(@Valid List<BarnRecordForm> list);
 }

+ 43 - 0
src/main/java/com/qmrb/system/service/IBarninRecordService.java

@@ -0,0 +1,43 @@
+package com.qmrb.system.service;
+
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.qmrb.system.pojo.entity.BarninRecord;
+import com.qmrb.system.pojo.form.BarninRecordForm;
+import com.qmrb.system.pojo.vo.BarninRecordVO;
+import com.qmrb.system.pojo.query.BarninRecordQuery;
+import com.baomidou.mybatisplus.extension.service.IService;
+import jakarta.validation.Valid;
+
+import java.util.List;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author xue
+ * @since 2025-03-03
+ */
+public interface IBarninRecordService extends IService<BarninRecord> {
+	
+	/**分页查询
+	 * */
+	public Page<BarninRecordVO> getPage(BarninRecordQuery queryParams);
+	
+
+	/**
+	 * 保存表单
+	 * */
+	public BarninRecordForm saveForm(@Valid BarninRecordForm form);
+	
+	/**更新
+	 * */
+	public boolean updateForm(Long id, BarninRecordForm form);
+	
+	/**获取表单数据
+	 * */
+	public BarninRecordForm getFormData(Long id);
+
+    List<BarninRecordForm> saveBatch(List<BarninRecordForm> list);
+}

+ 192 - 167
src/main/java/com/qmrb/system/service/impl/BarnRecordServiceImpl.java

@@ -7,17 +7,18 @@ import java.time.temporal.ChronoUnit;
 import java.util.*;
 import java.util.stream.Collectors;
 
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.bean.copier.CopyOptions;
 import cn.hutool.core.date.DateUnit;
 import cn.hutool.core.date.DateUtil;
 import com.qmrb.system.pojo.entity.CarPark;
 import com.qmrb.system.pojo.entity.MyCarPlateNumber;
 import com.qmrb.system.service.ICarParkService;
 import com.qmrb.system.service.IMyCarPlateNumberService;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.qmrb.system.common.enums.StatusEnum;
-import com.qmrb.system.pojo.vo.Option;
 import com.qmrb.system.converter.BarnRecordConverter;
 import com.qmrb.system.pojo.entity.BarnRecord;
 import com.qmrb.system.pojo.form.BarnRecordForm;
@@ -44,190 +45,214 @@ import jakarta.validation.Valid;
 @Service
 public class BarnRecordServiceImpl extends ServiceImpl<BarnRecordMapper, BarnRecord> implements IBarnRecordService {
 
-	@Autowired
-	private BarnRecordConverter converter;
-	
-	@Autowired
-	private IMyCarPlateNumberService myCarPlateNumberService;
-	
-	@Autowired
-	private ICarParkService carParkService;
-	
-
-	/**分页查询
-	 * */
-	@Override
-	public Page<BarnRecordVO> getPage(BarnRecordQuery queryParams) {
-		// 查询参数
+    @Autowired
+    private BarnRecordConverter converter;
+
+    @Autowired
+    private IMyCarPlateNumberService myCarPlateNumberService;
+
+    @Autowired
+    private ICarParkService carParkService;
+
+
+    /**
+     * 分页查询
+     */
+    @Override
+    public Page<BarnRecordVO> getPage(BarnRecordQuery queryParams) {
+        // 查询参数
         int pageNum = queryParams.getPageNum();
         int pageSize = queryParams.getPageSize();
-        //String keywords = queryParams.getKeywords();
-		LambdaQueryWrapper<BarnRecord> queryWrapper = new LambdaQueryWrapper<>();
-		if(queryParams.getUserId() != null){
-			// 根据用户id查找最新的车牌
-			List<MyCarPlateNumber> list = myCarPlateNumberService.list(new LambdaQueryWrapper<MyCarPlateNumber>().eq(MyCarPlateNumber::getUserId, queryParams.getUserId()).orderByDesc(MyCarPlateNumber::getCreateTime));
-			Assert.isTrue(CollectionUtil.isNotEmpty(list), "用户暂未绑定车牌!");
-			if(CollectionUtil.isNotEmpty(list)){
-				queryWrapper.eq(BarnRecord::getCarNumber,list.get(0).getPlateNumber());
-			}
-			
-		}
-		if (StrUtil.isNotBlank(queryParams.getCarNumber())) {
-			queryWrapper.eq(BarnRecord::getCarNumber,queryParams.getCarNumber());
-		}
-		queryWrapper.ge(StrUtil.isNotBlank(queryParams.getIntimeBegin()),BarnRecord::getInTime,queryParams.getIntimeBegin())
-				.le(StrUtil.isNotBlank(queryParams.getIntimeEnd()),BarnRecord::getInTime,queryParams.getIntimeEnd());
-		queryWrapper.ge(StrUtil.isNotBlank(queryParams.getOutTimeBegin()),BarnRecord::getOutTime,queryParams.getOutTimeBegin())
-				.le(StrUtil.isNotBlank(queryParams.getOutTimeEnd()),BarnRecord::getOutTime,queryParams.getOutTimeEnd());
-		
-		queryWrapper.orderByDesc(BarnRecord::getCreateTime);
+        // String keywords = queryParams.getKeywords();
+        LambdaQueryWrapper<BarnRecord> queryWrapper = new LambdaQueryWrapper<>();
+        if (queryParams.getUserId() != null) {
+            // 根据用户id查找最新的车牌
+            List<MyCarPlateNumber> list = myCarPlateNumberService.list(new LambdaQueryWrapper<MyCarPlateNumber>().eq(MyCarPlateNumber::getUserId, queryParams.getUserId()).orderByDesc(MyCarPlateNumber::getCreateTime));
+            Assert.isTrue(CollectionUtil.isNotEmpty(list), "用户暂未绑定车牌!");
+            if (CollectionUtil.isNotEmpty(list)) {
+                queryWrapper.eq(BarnRecord::getCarNumber, list.get(0).getPlateNumber());
+            }
+
+        }
+        if (StrUtil.isNotBlank(queryParams.getCarNumber())) {
+            queryWrapper.eq(BarnRecord::getCarNumber, queryParams.getCarNumber());
+        }
+        queryWrapper.ge(StrUtil.isNotBlank(queryParams.getIntimeBegin()), BarnRecord::getInTime, queryParams.getIntimeBegin()).le(StrUtil.isNotBlank(queryParams.getIntimeEnd()), BarnRecord::getInTime, queryParams.getIntimeEnd());
+        queryWrapper.ge(StrUtil.isNotBlank(queryParams.getOutTimeBegin()), BarnRecord::getOutTime, queryParams.getOutTimeBegin()).le(StrUtil.isNotBlank(queryParams.getOutTimeEnd()), BarnRecord::getOutTime, queryParams.getOutTimeEnd());
+
+        queryWrapper.orderByDesc(BarnRecord::getCreateTime);
         // 查询数据
-        Page<BarnRecord> dictItemPage = this.page(
-                new Page<>(pageNum, pageSize),
-				queryWrapper
-				
+        Page<BarnRecord> dictItemPage = this.page(new Page<>(pageNum, pageSize), queryWrapper
+
         );
-		List<CarPark> list = carParkService.list();
-		HashMap<Long, String> map = new HashMap<>();
-		if(CollectionUtil.isNotEmpty(list)){
-			list.stream().forEach(item->{
-				map.put(item.getId(),item.getName());
-			});
-		}
-		
+        List<CarPark> list = carParkService.list();
+        HashMap<Long, String> map = new HashMap<>();
+        if (CollectionUtil.isNotEmpty(list)) {
+            list.stream().forEach(item -> {
+                map.put(item.getId(), item.getName());
+            });
+        }
+
 
         // 实体转换
         Page<BarnRecordVO> pageResult = converter.entity2Page(dictItemPage);
 
-		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()));
-			}
-			if(record.getOutTime() != null){
-				record.setParkingTime(calculateTimeDifference(record.getInTime(),record.getOutTime()));
-			}else{
-				record.setParkingTime(calculateTimeDifference(record.getInTime(),new Date()));
-			}
-			barnRecords.add(record);
-		}
-		pageResult.setRecords(barnRecords);
+        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()));
+            }
+            if (record.getOutTime() != null) {
+                record.setParkingTime(calculateTimeDifference(record.getInTime(), record.getOutTime()));
+            } else {
+                record.setParkingTime(calculateTimeDifference(record.getInTime(), new Date()));
+            }
+            barnRecords.add(record);
+        }
+        pageResult.setRecords(barnRecords);
         return pageResult;
-	}
-
-	/**
-	 * 保存表单
-	 * */
-	@Override
-	public BarnRecordForm saveForm(@Valid BarnRecordForm form) {
-		// 实体对象转换 form->entity
-		BarnRecord entity = converter.form2Entity(form);
+    }
+
+    /**
+     * 保存表单
+     */
+    @Override
+    public BarnRecordForm saveForm(@Valid BarnRecordForm form) {
+        // 实体对象转换 form->entity
+        BarnRecord entity = converter.form2Entity(form);
         // 持久化
         this.save(entity);
         BarnRecordForm result = converter.entity2Form(entity);
         return result;
-	}
-
-	/**更新
-	 * */
-	@Override
-	public boolean updateForm(Long id, BarnRecordForm form) {
-		BarnRecord entity = converter.form2Entity(form);
-		entity.setId(id);
+    }
+
+    /**
+     * 更新
+     */
+    @Override
+    public boolean updateForm(Long id, BarnRecordForm form) {
+        BarnRecord entity = converter.form2Entity(form);
+        entity.setId(id);
         boolean result = this.updateById(entity);
         return result;
-	}
-
-	/**获取表单数据
-	 * */
-	@Override
-	public BarnRecordForm getFormData(Long id) {
-		// 获取entity
-		BarnRecord entity = this.getById(id);
+    }
+
+    /**
+     * 获取表单数据
+     */
+    @Override
+    public BarnRecordForm getFormData(Long id) {
+        // 获取entity
+        BarnRecord entity = this.getById(id);
         Assert.isTrue(entity != null, "岗亭端停车记录不存在");
 
         // 实体转换
         BarnRecordForm form = converter.entity2Form(entity);
         return form;
-	}
-
-	/**
-	 * 计算停车缴纳金额
-	 * @param id
-	 * @return
-	 */
-	@Override
-	public BarnRecordForm getCarParkUseLogOrder(Long id) {
-		// 获取entity
-		BarnRecord entity = this.getById(id);
-		Assert.isTrue(entity != null, "岗亭端停车记录不存在");
-
-		// 实体转换
-		BarnRecordForm form = converter.entity2Form(entity);
-
-		if(form.getOutTime() != null){
-			form.setParkingTime(calculateTimeDifference(form.getInTime(),form.getOutTime()));
-		}else{
-			form.setParkingTime(calculateTimeDifference(form.getInTime(),new Date()));
-		}
-		
-
-		List<CarPark> list = carParkService.list();
-		HashMap<Long, String> map = new HashMap<>();
-		if(CollectionUtil.isNotEmpty(list)){
-			list.stream().forEach(item->{
-				map.put(item.getId(),item.getName());
-			});
-		}
-		if(form.getCarParkId() != null && map.keySet().contains(form.getCarParkId())){
-			form.setCarParkName(map.get(form.getCarParkId()));
-		}
-		form.setPendingAmount(new BigDecimal(15));
-		form.setBillingAmount(new BigDecimal(15));
-		form.setReceivedAmount(BigDecimal.ZERO);
-		return form;
-	}
-
-
-	/**
-	 * 计算两个时间差(年,月,星期,日,时,分,秒)
-	 *
-	 * @param startDate
-	 * @param endDate
-	 * @return
-	 */
-	public static String calculateTimeDifference(Date startDate, Date endDate) {
-		if (null == startDate || null == endDate) {
-			return "";
-		}
-		ZoneId zoneId = ZoneId.systemDefault();
-		LocalDateTime fromDateTime = LocalDateTime.ofInstant(startDate.toInstant(), zoneId);
-		LocalDateTime toDateTime = LocalDateTime.ofInstant(endDate.toInstant(), zoneId);
-
-		LocalDateTime tempDateTime = LocalDateTime.from(fromDateTime);
-
-		long years = tempDateTime.until(toDateTime, ChronoUnit.YEARS);
-		tempDateTime = tempDateTime.plusYears(years);
-
-		long months = tempDateTime.until(toDateTime, ChronoUnit.MONTHS);
-		tempDateTime = tempDateTime.plusMonths(months);
-
-		long days = tempDateTime.until(toDateTime, ChronoUnit.DAYS);
-		tempDateTime = tempDateTime.plusDays(days);
-
-		long hours = tempDateTime.until(toDateTime, ChronoUnit.HOURS);
-		tempDateTime = tempDateTime.plusHours(hours);
-
-		long minutes = tempDateTime.until(toDateTime, ChronoUnit.MINUTES);
-		tempDateTime = tempDateTime.plusMinutes(minutes);
-
-		long seconds = tempDateTime.until(toDateTime, ChronoUnit.SECONDS);
-
-
-		return (DateUtil.between(endDate, startDate, DateUnit.HOUR) + ":")
-				+ (minutes + ":")
-				+ (seconds + "");
-
-	}
+    }
+
+    /**
+     * 计算停车缴纳金额
+     *
+     * @param id
+     * @return
+     */
+    @Override
+    public BarnRecordForm getCarParkUseLogOrder(Long id) {
+        // 获取entity
+        BarnRecord entity = this.getById(id);
+        Assert.isTrue(entity != null, "岗亭端停车记录不存在");
+
+        // 实体转换
+        BarnRecordForm form = converter.entity2Form(entity);
+
+        if (form.getOutTime() != null) {
+            form.setParkingTime(calculateTimeDifference(form.getInTime(), form.getOutTime()));
+        } else {
+            form.setParkingTime(calculateTimeDifference(form.getInTime(), new Date()));
+        }
+
+
+        List<CarPark> list = carParkService.list();
+        HashMap<Long, String> map = new HashMap<>();
+        if (CollectionUtil.isNotEmpty(list)) {
+            list.stream().forEach(item -> {
+                map.put(item.getId(), item.getName());
+            });
+        }
+        if (form.getCarParkId() != null && map.keySet().contains(form.getCarParkId())) {
+            form.setCarParkName(map.get(form.getCarParkId()));
+        }
+        form.setPendingAmount(new BigDecimal(15));
+        form.setBillingAmount(new BigDecimal(15));
+        form.setReceivedAmount(BigDecimal.ZERO);
+        return form;
+    }
+
+    @Override
+    public List<BarnRecordForm> saveBatchOrUpdate(@Valid List<BarnRecordForm> list) {
+        List<BarnRecord> saveList = new ArrayList<>();
+        List<BarnRecord> updateList = new ArrayList<>();
+        for (BarnRecordForm barnRecordForm : list) {
+            BarnRecord barnRecord = new BarnRecord();
+            BeanUtil.copyProperties(barnRecordForm, barnRecord);
+            // 根据placeNo,carNumber,inTime定位该条数据
+            List<BarnRecord> equalList = this.list(new LambdaQueryWrapper<BarnRecord>()
+                    .eq(BarnRecord::getPlaceNo, barnRecordForm.getPlaceNo())
+                    .eq(BarnRecord::getCarNumber, barnRecordForm.getCarNumber())
+                    .eq(BarnRecord::getInTime, barnRecordForm.getInTime())
+            );
+            if (CollectionUtil.isNotEmpty(equalList)) {
+                // 如果存在,则更新出场时间
+                updateList.add(barnRecord);
+            }else{
+                // 如果不存在,则新增
+                saveList.add(barnRecord);
+            }
+        }
+        boolean saveFlag = this.saveBatch(saveList);
+        boolean updateFlag = this.updateBatchById(updateList);
+        return list;
+    }
+
+
+    /**
+     * 计算两个时间差(年,月,星期,日,时,分,秒)
+     *
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    public static String calculateTimeDifference(Date startDate, Date endDate) {
+        if (null == startDate || null == endDate) {
+            return "";
+        }
+        ZoneId zoneId = ZoneId.systemDefault();
+        LocalDateTime fromDateTime = LocalDateTime.ofInstant(startDate.toInstant(), zoneId);
+        LocalDateTime toDateTime = LocalDateTime.ofInstant(endDate.toInstant(), zoneId);
+
+        LocalDateTime tempDateTime = LocalDateTime.from(fromDateTime);
+
+        long years = tempDateTime.until(toDateTime, ChronoUnit.YEARS);
+        tempDateTime = tempDateTime.plusYears(years);
+
+        long months = tempDateTime.until(toDateTime, ChronoUnit.MONTHS);
+        tempDateTime = tempDateTime.plusMonths(months);
+
+        long days = tempDateTime.until(toDateTime, ChronoUnit.DAYS);
+        tempDateTime = tempDateTime.plusDays(days);
+
+        long hours = tempDateTime.until(toDateTime, ChronoUnit.HOURS);
+        tempDateTime = tempDateTime.plusHours(hours);
+
+        long minutes = tempDateTime.until(toDateTime, ChronoUnit.MINUTES);
+        tempDateTime = tempDateTime.plusMinutes(minutes);
+
+        long seconds = tempDateTime.until(toDateTime, ChronoUnit.SECONDS);
+
+
+        return (DateUtil.between(endDate, startDate, DateUnit.HOUR) + ":") + (minutes + ":") + (seconds + "");
+
+    }
 
 }

+ 127 - 0
src/main/java/com/qmrb/system/service/impl/BarninRecordServiceImpl.java

@@ -0,0 +1,127 @@
+package com.qmrb.system.service.impl;
+
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollectionUtil;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.qmrb.system.converter.BarninRecordConverter;
+import com.qmrb.system.pojo.entity.BarnRecord;
+import com.qmrb.system.pojo.entity.BarninRecord;
+import com.qmrb.system.pojo.form.BarnRecordForm;
+import com.qmrb.system.pojo.form.BarninRecordForm;
+import com.qmrb.system.pojo.vo.BarninRecordVO;
+import com.qmrb.system.pojo.query.BarninRecordQuery;
+import com.qmrb.system.mapper.BarninRecordMapper;
+import com.qmrb.system.service.IBarninRecordService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+import cn.hutool.core.lang.Assert;
+import jakarta.validation.Valid;
+import lombok.RequiredArgsConstructor;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * <p>
+ * 服务实现类
+ * </p>
+ *
+ * @author xue
+ * @since 2025-03-03
+ */
+@Service
+@RequiredArgsConstructor
+public class BarninRecordServiceImpl extends ServiceImpl<BarninRecordMapper, BarninRecord> implements IBarninRecordService {
+
+    private final BarninRecordConverter converter;
+
+    /**
+     * 分页查询
+     */
+    @Override
+    public Page<BarninRecordVO> getPage(BarninRecordQuery queryParams) {
+        // 查询参数
+        int pageNum = queryParams.getPageNum();
+        int pageSize = queryParams.getPageSize();
+        // Integer status = queryParams.getStatus();
+        // String keywords = queryParams.getKeywords();
+
+        // 查询数据
+        Page<BarninRecord> dictItemPage = this.page(
+                new Page<>(pageNum, pageSize),
+                new LambdaQueryWrapper<BarninRecord>()
+                //.eq(status != null, BarninRecord::getStatus,status)
+                //.like(StrUtil.isNotBlank(keywords), BarninRecord::getCategoryName, keywords)
+        );
+
+        // 实体转换
+        Page<BarninRecordVO> pageResult = converter.entity2Page(dictItemPage);
+        return pageResult;
+    }
+
+
+    /**
+     * 保存表单
+     */
+    @Override
+    public BarninRecordForm saveForm(@Valid BarninRecordForm form) {
+        // 实体对象转换 form->entity
+        BarninRecord entity = converter.form2Entity(form);
+        // 持久化
+        this.save(entity);
+        BarninRecordForm result = converter.entity2Form(entity);
+        return result;
+    }
+
+    /**
+     * 更新
+     */
+    @Override
+    public boolean updateForm(Long id, BarninRecordForm form) {
+        BarninRecord entity = converter.form2Entity(form);
+        entity.setId(id);
+        boolean result = this.updateById(entity);
+        return result;
+    }
+
+    /**
+     * 获取表单数据
+     */
+    @Override
+    public BarninRecordForm getFormData(Long id) {
+        // 获取entity
+        BarninRecord entity = this.getById(id);
+        Assert.isTrue(entity != null, "不存在");
+
+        // 实体转换
+        BarninRecordForm form = converter.entity2Form(entity);
+        return form;
+    }
+
+    @Override
+    public List<BarninRecordForm> saveBatch(List<BarninRecordForm> list) {
+        List<BarninRecord> saveList = new ArrayList<>();
+        // 提取
+        List<Long> idsToDelete = list.stream()
+                .map(BarninRecordForm::getId)
+                .filter(id -> id != null)
+                .collect(Collectors.toList());
+
+        // 删除数据库中存在这些 id 的数据
+        if (!CollectionUtil.isEmpty(idsToDelete)) {
+            this.removeByIds(idsToDelete);
+        }
+        for (BarninRecordForm barninRecordForm : list) {
+            BarninRecord barninRecord = new BarninRecord();
+            BeanUtil.copyProperties(barninRecordForm, barninRecord);
+			saveList.add(barninRecord);
+        }
+        boolean saveFlag = this.saveBatch(saveList);
+        return list;
+    }
+
+}

+ 5 - 0
src/main/resources/mapper/BarninRecordMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.qmrb.system.mapper.BarninRecordMapper">
+
+</mapper>