Merge branch 'develop-business-css' of http://121.37.111.42:3000/ThbTech/JavaProjectRepo into develop-business-css
This commit is contained in:
commit
6c85a844dd
@ -8,6 +8,7 @@ import org.springframework.http.ResponseEntity;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.authentication.AnonymousAuthenticationToken;
|
import org.springframework.security.authentication.AnonymousAuthenticationToken;
|
||||||
|
|
||||||
@ -41,6 +42,7 @@ public class EventController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public ResponseEntity<Map<String, Object>> addEvent(@RequestBody Event event) {
|
public ResponseEntity<Map<String, Object>> addEvent(@RequestBody Event event) {
|
||||||
|
event.setModifier(currentUsername());
|
||||||
eventService.save(event);
|
eventService.save(event);
|
||||||
Event savedEvent = event;
|
Event savedEvent = event;
|
||||||
return ResponseEntity.ok(Map.of(
|
return ResponseEntity.ok(Map.of(
|
||||||
@ -61,9 +63,48 @@ public class EventController {
|
|||||||
@PutMapping
|
@PutMapping
|
||||||
public boolean update(@RequestBody Event event) {
|
public boolean update(@RequestBody Event event) {
|
||||||
event.setModifier(currentUsername());
|
event.setModifier(currentUsername());
|
||||||
|
event.setUpdatedAt(LocalDateTime.now());
|
||||||
return eventService.updateById(event);
|
return eventService.updateById(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量新增或修改事件
|
||||||
|
* @param events
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/batchSave")
|
||||||
|
@Transactional
|
||||||
|
public ResponseEntity<Map<String, Object>> batchSaveOrUpdateEvents(@RequestBody List<Event> events) {
|
||||||
|
String currentUser = currentUsername();
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
|
||||||
|
List<Event> savedEvents = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Event event : events) {
|
||||||
|
if (event.getEventId() != null && eventService.getById(event.getEventId()) != null) {
|
||||||
|
// 更新逻辑
|
||||||
|
event.setModifier(currentUser);
|
||||||
|
event.setUpdatedAt(now);
|
||||||
|
eventService.updateById(event);
|
||||||
|
savedEvents.add(event);
|
||||||
|
} else {
|
||||||
|
// 新增逻辑
|
||||||
|
event.setCreatedAt(now);
|
||||||
|
event.setModifier(currentUser);
|
||||||
|
event.setUpdatedAt(now);
|
||||||
|
eventService.save(event);
|
||||||
|
savedEvents.add(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseEntity.ok(Map.of(
|
||||||
|
"code", 0,
|
||||||
|
"msg", "批量保存或更新成功",
|
||||||
|
"data", savedEvents
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改 Event 的 attr_changes
|
* 修改 Event 的 attr_changes
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -36,6 +36,9 @@ public class Event implements Serializable {
|
|||||||
@TableField("created_at")
|
@TableField("created_at")
|
||||||
private LocalDateTime createdAt;
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
@TableField("updated_at")
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
|
||||||
@TableField("modifier")
|
@TableField("modifier")
|
||||||
private String modifier;
|
private String modifier;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user