From 361eb5148bee6c5f7563aeef41f4b2a9093b0cae Mon Sep 17 00:00:00 2001 From: chanhengseang Date: Sun, 18 May 2025 14:31:11 -0700 Subject: [PATCH] add event --- sport/src/main/java/com/srr/domain/Event.java | 111 +++++++++++++++++ .../main/java/com/srr/enumeration/Format.java | 7 ++ .../com/srr/repository/EventRepository.java | 28 +++++ .../java/com/srr/rest/EventController.java | 88 +++++++++++++ .../java/com/srr/service/EventService.java | 83 +++++++++++++ .../java/com/srr/service/dto/EventDto.java | 75 +++++++++++ .../srr/service/dto/EventQueryCriteria.java | 60 +++++++++ .../srr/service/impl/EventServiceImpl.java | 117 ++++++++++++++++++ .../srr/service/mapstruct/EventMapper.java | 32 +++++ .../src/main/resources/application.properties | 0 10 files changed, 601 insertions(+) create mode 100644 sport/src/main/java/com/srr/domain/Event.java create mode 100644 sport/src/main/java/com/srr/enumeration/Format.java create mode 100644 sport/src/main/java/com/srr/repository/EventRepository.java create mode 100644 sport/src/main/java/com/srr/rest/EventController.java create mode 100644 sport/src/main/java/com/srr/service/EventService.java create mode 100644 sport/src/main/java/com/srr/service/dto/EventDto.java create mode 100644 sport/src/main/java/com/srr/service/dto/EventQueryCriteria.java create mode 100644 sport/src/main/java/com/srr/service/impl/EventServiceImpl.java create mode 100644 sport/src/main/java/com/srr/service/mapstruct/EventMapper.java create mode 100644 sport/src/main/resources/application.properties diff --git a/sport/src/main/java/com/srr/domain/Event.java b/sport/src/main/java/com/srr/domain/Event.java new file mode 100644 index 00000000..810a8fd1 --- /dev/null +++ b/sport/src/main/java/com/srr/domain/Event.java @@ -0,0 +1,111 @@ +/* +* Copyright 2019-2025 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.srr.domain; + +import com.srr.enumeration.Format; +import lombok.Data; +import cn.hutool.core.bean.BeanUtil; +import io.swagger.annotations.ApiModelProperty; +import cn.hutool.core.bean.copier.CopyOptions; +import javax.persistence.*; +import javax.persistence.Entity; +import javax.persistence.Table; +import org.hibernate.annotations.*; +import java.sql.Timestamp; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** +* @website https://eladmin.vip +* @description / +* @author Chanheng +* @date 2025-05-18 +**/ +@Entity +@Data +@Table(name="event") +public class Event implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "`id`") + @ApiModelProperty(value = "id") + private Long id; + + @Column(name = "`name`",nullable = false) + @NotBlank + @ApiModelProperty(value = "名称") + private String name; + + @Column(name = "`description`") + @ApiModelProperty(value = "描述") + private String description; + + @Column(name = "`format`",nullable = false) + @NotNull + @Enumerated(EnumType.STRING) + @ApiModelProperty(value = "SINGLE, DOUBLE") + private Format format; + + @Column(name = "`max_player`") + @ApiModelProperty(value = "最大人数") + private Integer maxPlayer; + + @Column(name = "`location`") + @ApiModelProperty(value = "位置") + private String location; + + @Column(name = "`image`") + @ApiModelProperty(value = "图片") + private String image; + + @Column(name = "`create_time`") + @CreationTimestamp + @ApiModelProperty(value = "创建时间") + private Timestamp createTime; + + @Column(name = "`update_time`") + @UpdateTimestamp + @ApiModelProperty(value = "更新时间") + private Timestamp updateTime; + + @Column(name = "`sort`") + @ApiModelProperty(value = "排序") + private Integer sort; + + @Column(name = "`enabled`") + @ApiModelProperty(value = "是否启用") + private Boolean enabled; + + @Column(name = "`event_time`",nullable = false) + @NotNull + @ApiModelProperty(value = "时间") + private Timestamp eventTime; + + @Column(name = "`club_id`",nullable = false) + @NotNull + @ApiModelProperty(value = "clubId") + private Long clubId; + + @Column(name = "`create_by`") + @ApiModelProperty(value = "createBy") + private Long createBy; + + public void copy(Event source){ + BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); + } +} diff --git a/sport/src/main/java/com/srr/enumeration/Format.java b/sport/src/main/java/com/srr/enumeration/Format.java new file mode 100644 index 00000000..11e72eec --- /dev/null +++ b/sport/src/main/java/com/srr/enumeration/Format.java @@ -0,0 +1,7 @@ +package com.srr.enumeration; + +public enum Format { + SINGLE, + DOUBLE, + TEAM +} diff --git a/sport/src/main/java/com/srr/repository/EventRepository.java b/sport/src/main/java/com/srr/repository/EventRepository.java new file mode 100644 index 00000000..c22c6076 --- /dev/null +++ b/sport/src/main/java/com/srr/repository/EventRepository.java @@ -0,0 +1,28 @@ +/* +* Copyright 2019-2025 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.srr.repository; + +import com.srr.domain.Event; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +/** +* @website https://eladmin.vip +* @author Chanheng +* @date 2025-05-18 +**/ +public interface EventRepository extends JpaRepository, JpaSpecificationExecutor { +} \ No newline at end of file diff --git a/sport/src/main/java/com/srr/rest/EventController.java b/sport/src/main/java/com/srr/rest/EventController.java new file mode 100644 index 00000000..ea5d7401 --- /dev/null +++ b/sport/src/main/java/com/srr/rest/EventController.java @@ -0,0 +1,88 @@ +/* +* Copyright 2019-2025 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.srr.rest; + +import me.zhengjie.annotation.Log; +import com.srr.domain.Event; +import com.srr.service.EventService; +import com.srr.service.dto.EventQueryCriteria; +import org.springframework.data.domain.Pageable; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import io.swagger.annotations.*; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import me.zhengjie.utils.PageResult; +import com.srr.service.dto.EventDto; + +/** +* @website https://eladmin.vip +* @author Chanheng +* @date 2025-05-18 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "event") +@RequestMapping("/api/event") +public class EventController { + + private final EventService eventService; + + @ApiOperation("导出数据") + @GetMapping(value = "/download") + @PreAuthorize("@el.check('event:list')") + public void exportEvent(HttpServletResponse response, EventQueryCriteria criteria) throws IOException { + eventService.download(eventService.queryAll(criteria), response); + } + + @GetMapping + @ApiOperation("查询event") + @PreAuthorize("@el.check('event:list')") + public ResponseEntity> queryEvent(EventQueryCriteria criteria, Pageable pageable){ + return new ResponseEntity<>(eventService.queryAll(criteria,pageable),HttpStatus.OK); + } + + @PostMapping + @Log("新增event") + @ApiOperation("新增event") + @PreAuthorize("@el.check('event:add')") + public ResponseEntity createEvent(@Validated @RequestBody Event resources){ + eventService.create(resources); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + @PutMapping + @Log("修改event") + @ApiOperation("修改event") + @PreAuthorize("@el.check('event:edit')") + public ResponseEntity updateEvent(@Validated @RequestBody Event resources){ + eventService.update(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @DeleteMapping + @Log("删除event") + @ApiOperation("删除event") + @PreAuthorize("@el.check('event:del')") + public ResponseEntity deleteEvent(@ApiParam(value = "传ID数组[]") @RequestBody Long[] ids) { + eventService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } +} \ No newline at end of file diff --git a/sport/src/main/java/com/srr/service/EventService.java b/sport/src/main/java/com/srr/service/EventService.java new file mode 100644 index 00000000..7dea8628 --- /dev/null +++ b/sport/src/main/java/com/srr/service/EventService.java @@ -0,0 +1,83 @@ +/* +* Copyright 2019-2025 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.srr.service; + +import com.srr.domain.Event; +import com.srr.service.dto.EventDto; +import com.srr.service.dto.EventQueryCriteria; +import org.springframework.data.domain.Pageable; + +import java.util.List; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import me.zhengjie.utils.PageResult; + +/** +* @website https://eladmin.vip +* @description 服务接口 +* @author Chanheng +* @date 2025-05-18 +**/ +public interface EventService { + + /** + * 查询数据分页 + * @param criteria 条件 + * @param pageable 分页参数 + * @return Map + */ + PageResult queryAll(EventQueryCriteria criteria, Pageable pageable); + + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List queryAll(EventQueryCriteria criteria); + + /** + * 根据ID查询 + * @param id ID + * @return EventDto + */ + EventDto findById(Long id); + + /** + * 创建 + * @param resources / + */ + void create(Event resources); + + /** + * 编辑 + * @param resources / + */ + void update(Event resources); + + /** + * 多选删除 + * @param ids / + */ + void deleteAll(Long[] ids); + + /** + * 导出数据 + * @param all 待导出的数据 + * @param response / + * @throws IOException / + */ + void download(List all, HttpServletResponse response) throws IOException; +} \ No newline at end of file diff --git a/sport/src/main/java/com/srr/service/dto/EventDto.java b/sport/src/main/java/com/srr/service/dto/EventDto.java new file mode 100644 index 00000000..0d03c52c --- /dev/null +++ b/sport/src/main/java/com/srr/service/dto/EventDto.java @@ -0,0 +1,75 @@ +/* +* Copyright 2019-2025 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.srr.service.dto; + +import com.srr.enumeration.Format; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.sql.Timestamp; + +/** +* @website https://eladmin.vip +* @description / +* @author Chanheng +* @date 2025-05-18 +**/ +@Data +public class EventDto implements Serializable { + + @ApiModelProperty(value = "id") + private Long id; + + @ApiModelProperty(value = "名称") + private String name; + + @ApiModelProperty(value = "描述") + private String description; + + @ApiModelProperty(value = "SINGLE, DOUBLE") + private Format format; + + @ApiModelProperty(value = "最大人数") + private Integer maxPlayer; + + @ApiModelProperty(value = "位置") + private String location; + + @ApiModelProperty(value = "图片") + private String image; + + @ApiModelProperty(value = "创建时间") + private Timestamp createTime; + + @ApiModelProperty(value = "更新时间") + private Timestamp updateTime; + + @ApiModelProperty(value = "排序") + private Integer sort; + + @ApiModelProperty(value = "是否启用") + private Boolean enabled; + + @ApiModelProperty(value = "时间") + private Timestamp eventTime; + + @ApiModelProperty(value = "clubId") + private Long clubId; + + @ApiModelProperty(value = "createBy") + private Long createBy; +} \ No newline at end of file diff --git a/sport/src/main/java/com/srr/service/dto/EventQueryCriteria.java b/sport/src/main/java/com/srr/service/dto/EventQueryCriteria.java new file mode 100644 index 00000000..ffc8922b --- /dev/null +++ b/sport/src/main/java/com/srr/service/dto/EventQueryCriteria.java @@ -0,0 +1,60 @@ +/* +* Copyright 2019-2025 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.srr.service.dto; + +import com.srr.enumeration.Format; +import lombok.Data; +import java.sql.Timestamp; +import java.util.List; +import me.zhengjie.annotation.Query; +import io.swagger.annotations.ApiModelProperty; + +/** +* @website https://eladmin.vip +* @author Chanheng +* @date 2025-05-18 +**/ +@Data +public class EventQueryCriteria{ + + /** 精确 */ + @Query + @ApiModelProperty(value = "id") + private Long id; + + /** 模糊 */ + @Query(type = Query.Type.INNER_LIKE) + @ApiModelProperty(value = "名称") + private String name; + + /** 精确 */ + @Query + @ApiModelProperty(value = "SINGLE, DOUBLE") + private Format format; + + /** 精确 */ + @Query + @ApiModelProperty(value = "clubId") + private Long clubId; + + /** 精确 */ + @Query + @ApiModelProperty(value = "createBy") + private Long createBy; + /** BETWEEN */ + @Query(type = Query.Type.BETWEEN) + private List eventTime; +} \ No newline at end of file diff --git a/sport/src/main/java/com/srr/service/impl/EventServiceImpl.java b/sport/src/main/java/com/srr/service/impl/EventServiceImpl.java new file mode 100644 index 00000000..4bb77398 --- /dev/null +++ b/sport/src/main/java/com/srr/service/impl/EventServiceImpl.java @@ -0,0 +1,117 @@ +/* +* Copyright 2019-2025 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.srr.service.impl; + +import com.srr.domain.Event; +import me.zhengjie.utils.ValidationUtil; +import me.zhengjie.utils.FileUtil; +import lombok.RequiredArgsConstructor; +import com.srr.repository.EventRepository; +import com.srr.service.EventService; +import com.srr.service.dto.EventDto; +import com.srr.service.dto.EventQueryCriteria; +import com.srr.service.mapstruct.EventMapper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import me.zhengjie.utils.PageUtil; +import me.zhengjie.utils.QueryHelp; +import java.util.List; +import java.util.Map; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import me.zhengjie.utils.PageResult; + +/** +* @website https://eladmin.vip +* @description 服务实现 +* @author Chanheng +* @date 2025-05-18 +**/ +@Service +@RequiredArgsConstructor +public class EventServiceImpl implements EventService { + + private final EventRepository eventRepository; + private final EventMapper eventMapper; + + @Override + public PageResult queryAll(EventQueryCriteria criteria, Pageable pageable){ + Page page = eventRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + return PageUtil.toPage(page.map(eventMapper::toDto)); + } + + @Override + public List queryAll(EventQueryCriteria criteria){ + return eventMapper.toDto(eventRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); + } + + @Override + @Transactional + public EventDto findById(Long id) { + Event event = eventRepository.findById(id).orElseGet(Event::new); + ValidationUtil.isNull(event.getId(),"Event","id",id); + return eventMapper.toDto(event); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void create(Event resources) { + eventRepository.save(resources); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(Event resources) { + Event event = eventRepository.findById(resources.getId()).orElseGet(Event::new); + ValidationUtil.isNull( event.getId(),"Event","id",resources.getId()); + event.copy(resources); + eventRepository.save(event); + } + + @Override + public void deleteAll(Long[] ids) { + for (Long id : ids) { + eventRepository.deleteById(id); + } + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (EventDto event : all) { + Map map = new LinkedHashMap<>(); + map.put("名称", event.getName()); + map.put("描述", event.getDescription()); + map.put("SINGLE, DOUBLE", event.getFormat()); + map.put("最大人数", event.getMaxPlayer()); + map.put("位置", event.getLocation()); + map.put("图片", event.getImage()); + map.put("创建时间", event.getCreateTime()); + map.put("更新时间", event.getUpdateTime()); + map.put("排序", event.getSort()); + map.put("是否启用", event.getEnabled()); + map.put("时间", event.getEventTime()); + map.put(" clubId", event.getClubId()); + map.put(" createBy", event.getCreateBy()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } +} \ No newline at end of file diff --git a/sport/src/main/java/com/srr/service/mapstruct/EventMapper.java b/sport/src/main/java/com/srr/service/mapstruct/EventMapper.java new file mode 100644 index 00000000..41439900 --- /dev/null +++ b/sport/src/main/java/com/srr/service/mapstruct/EventMapper.java @@ -0,0 +1,32 @@ +/* +* Copyright 2019-2025 Zheng Jie +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +package com.srr.service.mapstruct; + +import me.zhengjie.base.BaseMapper; +import com.srr.domain.Event; +import com.srr.service.dto.EventDto; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** +* @website https://eladmin.vip +* @author Chanheng +* @date 2025-05-18 +**/ +@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface EventMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/sport/src/main/resources/application.properties b/sport/src/main/resources/application.properties new file mode 100644 index 00000000..e69de29b