Bladeren bron

车辆管理新增批量修改有效期接口

dzx 1 jaar geleden
bovenliggende
commit
6f7d5c5c3b

+ 26 - 1
src/main/java/com/xjrsoft/module/personnel/controller/CarMessageApplyController.java

@@ -18,6 +18,7 @@ import com.xjrsoft.module.organization.entity.UserDeptRelation;
 import com.xjrsoft.module.personnel.dto.AddCarMessageApplyDto;
 import com.xjrsoft.module.personnel.dto.CarMessageApplyPageDto;
 import com.xjrsoft.module.personnel.dto.UpdateCarMessageApplyDto;
+import com.xjrsoft.module.personnel.dto.UpdateCarMessageApplyEndTimeDto;
 import com.xjrsoft.module.personnel.entity.CarMessageApply;
 import com.xjrsoft.module.personnel.service.ICarMessageApplyService;
 import com.xjrsoft.module.personnel.vo.CarMessageApplyPageVo;
@@ -37,6 +38,10 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.validation.Valid;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -115,7 +120,7 @@ public class CarMessageApplyController {
     public RT<Boolean> add(@Valid @RequestBody AddCarMessageApplyDto dto){
         CarMessageApply carMessageApply = BeanUtil.toBean(dto, CarMessageApply.class);
         boolean isSuccess = carMessageApplyService.save(carMessageApply);
-    return RT.ok(isSuccess);
+        return RT.ok(isSuccess);
     }
 
     @PutMapping
@@ -147,4 +152,24 @@ public class CarMessageApplyController {
         return R.ok(true);
     }
 
+    @PostMapping("/update-end-time-batch")
+    @ApiOperation(value = "批量修改有效期")
+    @SaCheckPermission("carmessageapply:add")
+    public RT<Boolean> add(@Valid @RequestBody UpdateCarMessageApplyEndTimeDto dto){
+
+        List<CarMessageApply> list = carMessageApplyService.listByIds(dto.getIds());
+        for (CarMessageApply carMessageApply : list) {
+            ZonedDateTime zonedDateTime = dto.getEndTime().atStartOfDay(ZoneId.systemDefault());
+
+            // 将 ZonedDateTime 转换为 Instant
+            Instant instant = zonedDateTime.toInstant();
+
+            // 将 Instant 转换为 Date
+            Date date = Date.from(instant);
+            carMessageApply.setEndTime(date);
+        }
+        boolean updated = carMessageApplyService.updateBatchById(list);
+        return RT.ok(updated);
+    }
+
 }

+ 33 - 0
src/main/java/com/xjrsoft/module/personnel/dto/UpdateCarMessageApplyEndTimeDto.java

@@ -0,0 +1,33 @@
+package com.xjrsoft.module.personnel.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.time.LocalDate;
+import java.util.Date;
+import java.util.List;
+
+
+/**
+* @title: 车辆信息审核
+* @Author dzx
+* @Date: 2024-05-12
+* @Version 1.0
+*/
+@Data
+public class UpdateCarMessageApplyEndTimeDto{
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+    * 主键
+    */
+    @ApiModelProperty("主键")
+    private List<Long> ids;
+
+
+    @DateTimeFormat(pattern = "yyyy-MM-dd")
+    @ApiModelProperty("有效期结束日期")
+    private LocalDate endTime;
+}