From 28f6c9038151da9d8f457d11b1d6748fbdac2358 Mon Sep 17 00:00:00 2001 From: chanhengseang Date: Sat, 17 May 2025 18:22:44 -0700 Subject: [PATCH] add sport --- eladmin-system/pom.xml | 5 + .../main/resources/db/migration/V2__event.sql | 54 ++++++++ .../resources/db/migration/V3__player.sql | 12 ++ pom.xml | 1 + sport/index.vue | 122 ++++++++++++++++++ sport/pom.xml | 29 +++++ sport/sport.js | 27 ++++ sport/src/main/java/com/srr/domain/Sport.java | 82 ++++++++++++ .../com/srr/repository/SportRepository.java | 28 ++++ .../java/com/srr/rest/SportController.java | 94 ++++++++++++++ .../java/com/srr/service/SportService.java | 83 ++++++++++++ .../java/com/srr/service/dto/SportDto.java | 55 ++++++++ .../srr/service/dto/SportQueryCriteria.java | 46 +++++++ .../srr/service/impl/SportServiceImpl.java | 111 ++++++++++++++++ .../srr/service/mapstruct/SportMapper.java | 32 +++++ 15 files changed, 781 insertions(+) create mode 100644 eladmin-system/src/main/resources/db/migration/V2__event.sql create mode 100644 eladmin-system/src/main/resources/db/migration/V3__player.sql create mode 100644 sport/index.vue create mode 100644 sport/pom.xml create mode 100644 sport/sport.js create mode 100644 sport/src/main/java/com/srr/domain/Sport.java create mode 100644 sport/src/main/java/com/srr/repository/SportRepository.java create mode 100644 sport/src/main/java/com/srr/rest/SportController.java create mode 100644 sport/src/main/java/com/srr/service/SportService.java create mode 100644 sport/src/main/java/com/srr/service/dto/SportDto.java create mode 100644 sport/src/main/java/com/srr/service/dto/SportQueryCriteria.java create mode 100644 sport/src/main/java/com/srr/service/impl/SportServiceImpl.java create mode 100644 sport/src/main/java/com/srr/service/mapstruct/SportMapper.java diff --git a/eladmin-system/pom.xml b/eladmin-system/pom.xml index 667dacb6..2a295953 100644 --- a/eladmin-system/pom.xml +++ b/eladmin-system/pom.xml @@ -36,6 +36,11 @@ eladmin-tools 2.7 + + me.zhengjie + sport + 2.7 + diff --git a/eladmin-system/src/main/resources/db/migration/V2__event.sql b/eladmin-system/src/main/resources/db/migration/V2__event.sql new file mode 100644 index 00000000..85a130d0 --- /dev/null +++ b/eladmin-system/src/main/resources/db/migration/V2__event.sql @@ -0,0 +1,54 @@ +create table sport +( + id bigint auto_increment primary key, + name varchar(32) not null comment '名称', + description varchar(255) null comment '描述', + create_time datetime null comment '创建时间', + update_time datetime null comment '更新时间', + icon varchar(255) null comment '图标', + sort int null comment '排序', + enabled bit null comment '是否启用' +); + +create table club +( + id bigint auto_increment primary key, + name varchar(32) not null comment '名称', + description varchar(255) null comment '描述', + create_time datetime null comment '创建时间', + update_time datetime null comment '更新时间', + icon varchar(255) null comment '图标', + sort int null comment '排序', + enabled bit null comment '是否启用', + location varchar(255) null comment '位置', + longitude double null comment '经度', + latitude double null comment '纬度' +); + +create table court +( + id bigint auto_increment primary key, + club_id bigint null references club (id), + sport_id bigint null references sport (id), + create_time datetime null comment '创建时间', + update_time datetime null comment '更新时间', + amount int not null default 0 comment '数量' +); + +create table event +( + id bigint auto_increment primary key, + name varchar(32) not null comment '名称', + description varchar(255) null comment '描述', + format enum ('SINGLE', 'DOUBLE', 'TEAM') not null, + max_player int null comment '最大人数', + location varchar(255) null comment '位置', + image varchar(255) null comment '图片', + create_time datetime null comment '创建时间', + update_time datetime null comment '更新时间', + sort int null comment '排序', + enabled bit null comment '是否启用', + event_time datetime null comment '时间', + club_id bigint null references club (id), + create_by bigint null references sys_user (user_id) +); diff --git a/eladmin-system/src/main/resources/db/migration/V3__player.sql b/eladmin-system/src/main/resources/db/migration/V3__player.sql new file mode 100644 index 00000000..fcbf0c5d --- /dev/null +++ b/eladmin-system/src/main/resources/db/migration/V3__player.sql @@ -0,0 +1,12 @@ +create table player( + id bigint auto_increment primary key, + name varchar(32) not null comment '名称', + description varchar(255) null comment '描述', + latitude double null comment '纬度', + longitude double null comment '经度', + profile_image varchar(255) null comment '图片', + create_time datetime null comment '创建时间', + update_time datetime null comment '更新时间', + rate_score double null comment '评分', + user_id int8 null references sys_user (user_id) +) \ No newline at end of file diff --git a/pom.xml b/pom.xml index 1e82adb2..cb0c6d03 100644 --- a/pom.xml +++ b/pom.xml @@ -13,6 +13,7 @@ eladmin-system eladmin-tools eladmin-generator + sport ELADMIN 后台管理 diff --git a/sport/index.vue b/sport/index.vue new file mode 100644 index 00000000..9998e685 --- /dev/null +++ b/sport/index.vue @@ -0,0 +1,122 @@ + + + + + diff --git a/sport/pom.xml b/sport/pom.xml new file mode 100644 index 00000000..b1cecd3f --- /dev/null +++ b/sport/pom.xml @@ -0,0 +1,29 @@ + + + + eladmin + me.zhengjie + 2.7 + + 4.0.0 + + 5.8.35 + + + sport + sport + + + + + cn.hutool + hutool-all + ${hutool.version} + + + me.zhengjie + eladmin-tools + 2.7 + + + \ No newline at end of file diff --git a/sport/sport.js b/sport/sport.js new file mode 100644 index 00000000..98f56f4f --- /dev/null +++ b/sport/sport.js @@ -0,0 +1,27 @@ +import request from '@/utils/request' + +export function add(data) { + return request({ + url: 'api/sport', + method: 'post', + data + }) +} + +export function del(ids) { + return request({ + url: 'api/sport/', + method: 'delete', + data: ids + }) +} + +export function edit(data) { + return request({ + url: 'api/sport', + method: 'put', + data + }) +} + +export default { add, edit, del } diff --git a/sport/src/main/java/com/srr/domain/Sport.java b/sport/src/main/java/com/srr/domain/Sport.java new file mode 100644 index 00000000..8904c084 --- /dev/null +++ b/sport/src/main/java/com/srr/domain/Sport.java @@ -0,0 +1,82 @@ +/* +* 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 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.validation.constraints.*; +import javax.persistence.Entity; +import javax.persistence.Table; +import org.hibernate.annotations.*; +import java.sql.Timestamp; +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** +* @website https://eladmin.vip +* @description / +* @author Chanheng +* @date 2025-05-17 +**/ +@Entity +@Data +@Table(name="sport") +public class Sport 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 = "`create_time`") + @CreationTimestamp + @ApiModelProperty(value = "创建时间") + private Timestamp createTime; + + @Column(name = "`update_time`") + @UpdateTimestamp + @ApiModelProperty(value = "更新时间") + private Timestamp updateTime; + + @Column(name = "`icon`") + @ApiModelProperty(value = "图标") + private String icon; + + @Column(name = "`sort`") + @ApiModelProperty(value = "排序") + private Integer sort; + + @Column(name = "`enabled`") + @ApiModelProperty(value = "是否启用") + private Boolean enabled; + + public void copy(Sport source){ + BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); + } +} diff --git a/sport/src/main/java/com/srr/repository/SportRepository.java b/sport/src/main/java/com/srr/repository/SportRepository.java new file mode 100644 index 00000000..8003c6b9 --- /dev/null +++ b/sport/src/main/java/com/srr/repository/SportRepository.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.Sport; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +/** +* @website https://eladmin.vip +* @author Chanheng +* @date 2025-05-17 +**/ +public interface SportRepository extends JpaRepository, JpaSpecificationExecutor { +} \ No newline at end of file diff --git a/sport/src/main/java/com/srr/rest/SportController.java b/sport/src/main/java/com/srr/rest/SportController.java new file mode 100644 index 00000000..7cb6afc4 --- /dev/null +++ b/sport/src/main/java/com/srr/rest/SportController.java @@ -0,0 +1,94 @@ +/* +* 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.Sport; +import com.srr.service.SportService; +import com.srr.service.dto.SportQueryCriteria; +import me.zhengjie.annotation.rest.AnonymousGetMapping; +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.SportDto; + +/** +* @website https://eladmin.vip +* @author Chanheng +* @date 2025-05-17 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "sport") +@RequestMapping("/api/sport") +public class SportController { + + private final SportService sportService; + + @AnonymousGetMapping(value = "/ping") + public String ping() { + return "pong"; + } + + @ApiOperation("导出数据") + @GetMapping(value = "/download") + @PreAuthorize("@el.check('sport:list')") + public void exportSport(HttpServletResponse response, SportQueryCriteria criteria) throws IOException { + sportService.download(sportService.queryAll(criteria), response); + } + + @GetMapping + @ApiOperation("查询sport") + @PreAuthorize("@el.check('sport:list')") + public ResponseEntity> querySport(SportQueryCriteria criteria, Pageable pageable){ + return new ResponseEntity<>(sportService.queryAll(criteria,pageable),HttpStatus.OK); + } + + @PostMapping + @Log("新增sport") + @ApiOperation("新增sport") + @PreAuthorize("@el.check('sport:add')") + public ResponseEntity createSport(@Validated @RequestBody Sport resources){ + sportService.create(resources); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + @PutMapping + @Log("修改sport") + @ApiOperation("修改sport") + @PreAuthorize("@el.check('sport:edit')") + public ResponseEntity updateSport(@Validated @RequestBody Sport resources){ + sportService.update(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @DeleteMapping + @Log("删除sport") + @ApiOperation("删除sport") + @PreAuthorize("@el.check('sport:del')") + public ResponseEntity deleteSport(@ApiParam(value = "传ID数组[]") @RequestBody Long[] ids) { + sportService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } +} \ No newline at end of file diff --git a/sport/src/main/java/com/srr/service/SportService.java b/sport/src/main/java/com/srr/service/SportService.java new file mode 100644 index 00000000..5c4260c8 --- /dev/null +++ b/sport/src/main/java/com/srr/service/SportService.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.Sport; +import com.srr.service.dto.SportDto; +import com.srr.service.dto.SportQueryCriteria; +import org.springframework.data.domain.Pageable; +import java.util.Map; +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-17 +**/ +public interface SportService { + + /** + * 查询数据分页 + * @param criteria 条件 + * @param pageable 分页参数 + * @return Map + */ + PageResult queryAll(SportQueryCriteria criteria, Pageable pageable); + + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List queryAll(SportQueryCriteria criteria); + + /** + * 根据ID查询 + * @param id ID + * @return SportDto + */ + SportDto findById(Long id); + + /** + * 创建 + * @param resources / + */ + void create(Sport resources); + + /** + * 编辑 + * @param resources / + */ + void update(Sport 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/SportDto.java b/sport/src/main/java/com/srr/service/dto/SportDto.java new file mode 100644 index 00000000..f66f2ae9 --- /dev/null +++ b/sport/src/main/java/com/srr/service/dto/SportDto.java @@ -0,0 +1,55 @@ +/* +* 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 lombok.Data; +import java.sql.Timestamp; +import java.io.Serializable; +import io.swagger.annotations.ApiModelProperty; + +/** +* @website https://eladmin.vip +* @description / +* @author Chanheng +* @date 2025-05-17 +**/ +@Data +public class SportDto implements Serializable { + + @ApiModelProperty(value = "id") + private Long id; + + @ApiModelProperty(value = "名称") + private String name; + + @ApiModelProperty(value = "描述") + private String description; + + @ApiModelProperty(value = "创建时间") + private Timestamp createTime; + + @ApiModelProperty(value = "更新时间") + private Timestamp updateTime; + + @ApiModelProperty(value = "图标") + private String icon; + + @ApiModelProperty(value = "排序") + private Integer sort; + + @ApiModelProperty(value = "是否启用") + private Boolean enabled; +} \ No newline at end of file diff --git a/sport/src/main/java/com/srr/service/dto/SportQueryCriteria.java b/sport/src/main/java/com/srr/service/dto/SportQueryCriteria.java new file mode 100644 index 00000000..92972699 --- /dev/null +++ b/sport/src/main/java/com/srr/service/dto/SportQueryCriteria.java @@ -0,0 +1,46 @@ +/* +* 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 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-17 +**/ +@Data +public class SportQueryCriteria{ + + /** 模糊 */ + @Query(type = Query.Type.INNER_LIKE) + @ApiModelProperty(value = "名称") + private String name; + + /** 精确 */ + @Query + @ApiModelProperty(value = "创建时间") + private Timestamp createTime; + + /** 精确 */ + @Query + @ApiModelProperty(value = "是否启用") + private Boolean enabled; +} \ No newline at end of file diff --git a/sport/src/main/java/com/srr/service/impl/SportServiceImpl.java b/sport/src/main/java/com/srr/service/impl/SportServiceImpl.java new file mode 100644 index 00000000..eb9fe8af --- /dev/null +++ b/sport/src/main/java/com/srr/service/impl/SportServiceImpl.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.service.impl; + +import com.srr.domain.Sport; +import me.zhengjie.utils.ValidationUtil; +import me.zhengjie.utils.FileUtil; +import lombok.RequiredArgsConstructor; +import com.srr.repository.SportRepository; +import com.srr.service.SportService; +import com.srr.service.dto.SportDto; +import com.srr.service.dto.SportQueryCriteria; +import com.srr.service.mapstruct.SportMapper; +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-17 +**/ +@Service +@RequiredArgsConstructor +public class SportServiceImpl implements SportService { + + private final SportRepository sportRepository; + private final SportMapper sportMapper; + + @Override + public PageResult queryAll(SportQueryCriteria criteria, Pageable pageable){ + Page page = sportRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + return PageUtil.toPage(page.map(sportMapper::toDto)); + } + + @Override + public List queryAll(SportQueryCriteria criteria){ + return sportMapper.toDto(sportRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); + } + + @Override + @Transactional + public SportDto findById(Long id) { + Sport sport = sportRepository.findById(id).orElseGet(Sport::new); + ValidationUtil.isNull(sport.getId(),"Sport","id",id); + return sportMapper.toDto(sport); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void create(Sport resources) { + sportRepository.save(resources); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(Sport resources) { + Sport sport = sportRepository.findById(resources.getId()).orElseGet(Sport::new); + ValidationUtil.isNull( sport.getId(),"Sport","id",resources.getId()); + sport.copy(resources); + sportRepository.save(sport); + } + + @Override + public void deleteAll(Long[] ids) { + for (Long id : ids) { + sportRepository.deleteById(id); + } + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (SportDto sport : all) { + Map map = new LinkedHashMap<>(); + map.put("名称", sport.getName()); + map.put("描述", sport.getDescription()); + map.put("创建时间", sport.getCreateTime()); + map.put("更新时间", sport.getUpdateTime()); + map.put("图标", sport.getIcon()); + map.put("排序", sport.getSort()); + map.put("是否启用", sport.getEnabled()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } +} \ No newline at end of file diff --git a/sport/src/main/java/com/srr/service/mapstruct/SportMapper.java b/sport/src/main/java/com/srr/service/mapstruct/SportMapper.java new file mode 100644 index 00000000..11deff14 --- /dev/null +++ b/sport/src/main/java/com/srr/service/mapstruct/SportMapper.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.Sport; +import com.srr.service.dto.SportDto; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** +* @website https://eladmin.vip +* @author Chanheng +* @date 2025-05-17 +**/ +@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface SportMapper extends BaseMapper { + +} \ No newline at end of file