add event

pull/882/head
chanhengseang 2025-05-18 14:31:11 -07:00
parent 55c69c94b0
commit 361eb5148b
10 changed files with 601 additions and 0 deletions

View File

@ -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));
}
}

View File

@ -0,0 +1,7 @@
package com.srr.enumeration;
public enum Format {
SINGLE,
DOUBLE,
TEAM
}

View File

@ -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<Event, Long>, JpaSpecificationExecutor<Event> {
}

View File

@ -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<PageResult<EventDto>> 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<Object> 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<Object> 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<Object> deleteEvent(@ApiParam(value = "传ID数组[]") @RequestBody Long[] ids) {
eventService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@ -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<String,Object>
*/
PageResult<EventDto> queryAll(EventQueryCriteria criteria, Pageable pageable);
/**
*
* @param criteria
* @return List<EventDto>
*/
List<EventDto> 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<EventDto> all, HttpServletResponse response) throws IOException;
}

View File

@ -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;
}

View File

@ -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<Timestamp> eventTime;
}

View File

@ -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<EventDto> queryAll(EventQueryCriteria criteria, Pageable pageable){
Page<Event> page = eventRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(eventMapper::toDto));
}
@Override
public List<EventDto> 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<EventDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (EventDto event : all) {
Map<String,Object> 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);
}
}

View File

@ -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<EventDto, Event> {
}