feat: 添加教练退出/复职/新增功能,修复OGNL表达式语法错误
This commit is contained in:
parent
431ee1eb35
commit
ef18b12eb1
8 changed files with 140 additions and 19 deletions
2
pom.xml
2
pom.xml
|
|
@ -65,7 +65,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springdoc</groupId>
|
<groupId>org.springdoc</groupId>
|
||||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||||
<version>2.5.0</version>
|
<version>2.8.16</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.pagehelper</groupId>
|
<groupId>com.github.pagehelper</groupId>
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,13 @@
|
||||||
package edu.situ.stlserver.controller;
|
package edu.situ.stlserver.controller;
|
||||||
|
|
||||||
|
|
||||||
import edu.situ.stlserver.dao.CoachMapper;
|
import edu.situ.stlserver.model.dto.CoachAddDTO;
|
||||||
import edu.situ.stlserver.model.entity.Coach;
|
import edu.situ.stlserver.model.dto.CoachQueryDTO;
|
||||||
import edu.situ.stlserver.model.vo.HttpResult;
|
import edu.situ.stlserver.model.vo.HttpResult;
|
||||||
import edu.situ.stlserver.service.CoachService;
|
import edu.situ.stlserver.service.CoachService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/coach")
|
@RequestMapping("/coach")
|
||||||
|
|
@ -19,8 +18,29 @@ public class CoachController {
|
||||||
|
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public HttpResult getByPage(Integer page , Integer limit , Coach coach)
|
public HttpResult getByPage(Integer page , Integer limit , CoachQueryDTO coachQueryDTO)
|
||||||
{
|
{
|
||||||
return HttpResult.success(coachService.getByPage( page,limit,coach));
|
return HttpResult.success(coachService.getByPage( page,limit, coachQueryDTO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}/quit")
|
||||||
|
public HttpResult quit(@PathVariable Integer id)
|
||||||
|
{
|
||||||
|
coachService.quit(id);
|
||||||
|
return HttpResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}/rejoin")
|
||||||
|
public HttpResult rejoin(@PathVariable Integer id)
|
||||||
|
{
|
||||||
|
coachService.rejoin(id);
|
||||||
|
return HttpResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
|
public HttpResult add(CoachAddDTO coachAddDTO)
|
||||||
|
{
|
||||||
|
coachService.add(coachAddDTO);
|
||||||
|
return HttpResult.success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,8 @@ package edu.situ.stlserver.dao;
|
||||||
|
|
||||||
|
|
||||||
import edu.situ.stlserver.model.entity.Coach;
|
import edu.situ.stlserver.model.entity.Coach;
|
||||||
import edu.situ.stlserver.model.query.CoachQuery;
|
import edu.situ.stlserver.model.dto.CoachQueryDTO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.*;
|
||||||
import org.apache.ibatis.annotations.Param;
|
|
||||||
import org.apache.ibatis.annotations.Select;
|
|
||||||
import org.apache.ibatis.annotations.Update;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -32,8 +29,16 @@ public interface CoachMapper {
|
||||||
"</where>",
|
"</where>",
|
||||||
"</script>"
|
"</script>"
|
||||||
})
|
})
|
||||||
List<Coach> select(CoachQuery coachQuery);
|
List<Coach> select(CoachQueryDTO coachQueryDTO);
|
||||||
|
|
||||||
@Update(value = "UPDATE `coaches` SET `quit_date` = #{quitDate} WHERE `id` = #{id}")
|
@Update(value = "UPDATE `coaches` SET `quit_date` = #{quitDate} WHERE `id` = #{id}")
|
||||||
void quit(@Param("id") Integer id,@Param("quitDate") String quitDate);
|
void quit(@Param("id") Integer id,@Param("quitDate") String quitDate);
|
||||||
|
|
||||||
|
|
||||||
|
@Update(value = "UPDATE `coaches` SET `quit_date` = null WHERE `id` = #{id}")
|
||||||
|
void rejoin(Integer id);
|
||||||
|
|
||||||
|
@Insert(value = "INSERT INTO `coaches`(`name`, `sex`, `remark`, `avatar`) VALUES (#{name}, #{sex}, #{remark}, #{avatar})")
|
||||||
|
@Options(useGeneratedKeys = true, keyProperty = "id" , keyColumn = "id")
|
||||||
|
void insert(Coach coach);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
17
src/main/java/edu/situ/stlserver/model/dto/CoachAddDTO.java
Normal file
17
src/main/java/edu/situ/stlserver/model/dto/CoachAddDTO.java
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
package edu.situ.stlserver.model.dto;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class CoachAddDTO {
|
||||||
|
private String name;
|
||||||
|
private Integer sex;
|
||||||
|
private String remark;
|
||||||
|
private MultipartFile file;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package edu.situ.stlserver.model.dto;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
|
||||||
|
@ToString
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
public class CoachQueryDTO {
|
||||||
|
private String name;
|
||||||
|
private Integer sex;
|
||||||
|
private Integer status;
|
||||||
|
}
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
package edu.situ.stlserver.service;
|
package edu.situ.stlserver.service;
|
||||||
|
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import edu.situ.stlserver.model.dto.CoachAddDTO;
|
||||||
import edu.situ.stlserver.model.entity.Coach;
|
import edu.situ.stlserver.model.entity.Coach;
|
||||||
|
import edu.situ.stlserver.model.dto.CoachQueryDTO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -9,5 +11,8 @@ import java.util.List;
|
||||||
|
|
||||||
public interface CoachService {
|
public interface CoachService {
|
||||||
List<Coach> getAll();
|
List<Coach> getAll();
|
||||||
PageInfo<Coach> getByPage(Integer page,Integer limit,Coach coach);
|
PageInfo<Coach> getByPage(Integer page, Integer limit, CoachQueryDTO coachQueryDTO);
|
||||||
|
void quit(Integer id);
|
||||||
|
void rejoin(Integer id);
|
||||||
|
void add(CoachAddDTO coachAddDTO);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,30 @@
|
||||||
package edu.situ.stlserver.service.impl;
|
package edu.situ.stlserver.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import edu.situ.stlserver.dao.CoachMapper;
|
import edu.situ.stlserver.dao.CoachMapper;
|
||||||
|
import edu.situ.stlserver.model.dto.CoachAddDTO;
|
||||||
import edu.situ.stlserver.model.entity.Coach;
|
import edu.situ.stlserver.model.entity.Coach;
|
||||||
|
import edu.situ.stlserver.model.dto.CoachQueryDTO;
|
||||||
import edu.situ.stlserver.service.CoachService;
|
import edu.situ.stlserver.service.CoachService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class CoachServiceImpl implements CoachService {
|
public class CoachServiceImpl implements CoachService {
|
||||||
|
|
||||||
|
@Value("${upload.base-path}")
|
||||||
|
private String baseUploadPath;
|
||||||
|
@Value("${upload.image.coach}")
|
||||||
|
private String coachUploadPath;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CoachMapper coachMapper;
|
private CoachMapper coachMapper;
|
||||||
|
|
||||||
|
|
@ -22,10 +34,53 @@ public class CoachServiceImpl implements CoachService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageInfo<Coach> getByPage(Integer page, Integer limit, Coach coach) {
|
public PageInfo<Coach> getByPage(Integer page, Integer limit, CoachQueryDTO coachQueryDTO) {
|
||||||
if(page == null) page=1;
|
if(page == null) page=1;
|
||||||
if(limit == null) limit=10;
|
if(limit == null) limit=10;
|
||||||
PageHelper.startPage(page,limit);
|
PageHelper.startPage(page,limit);
|
||||||
return new PageInfo<>(coachMapper.select(coach));
|
return new PageInfo<>(coachMapper.select(coachQueryDTO));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void quit(Integer id) {
|
||||||
|
coachMapper.quit(id, DateUtil.today());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rejoin(Integer id) {
|
||||||
|
coachMapper.rejoin(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void add(CoachAddDTO coachAddDTO) {
|
||||||
|
Coach coach = new Coach();
|
||||||
|
coach.setName(coachAddDTO.getName());
|
||||||
|
coach.setSex(coachAddDTO.getSex());
|
||||||
|
coach.setRemark(coachAddDTO.getRemark());
|
||||||
|
String avatar;
|
||||||
|
System.out.println(coachAddDTO.getFile());
|
||||||
|
if (coachAddDTO.getFile() != null && !coachAddDTO.getFile().isEmpty())
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
avatar = saveAvatar(coachAddDTO.getFile());
|
||||||
|
coach.setAvatar(avatar);
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException("保存头像失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
coachMapper.insert(coach);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private String saveAvatar(MultipartFile file) throws Exception {
|
||||||
|
String originFilename = file.getOriginalFilename();
|
||||||
|
String suffix = originFilename.substring(originFilename.lastIndexOf("."));
|
||||||
|
String filename = UUID.randomUUID().toString() + suffix;
|
||||||
|
File dir = new File(baseUploadPath + coachUploadPath);
|
||||||
|
if (!dir.exists()) {dir.mkdirs();}
|
||||||
|
file.transferTo(new File(baseUploadPath + coachUploadPath + filename));
|
||||||
|
return coachUploadPath + filename;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,5 +25,8 @@ mybatis:
|
||||||
map-underscore-to-camel-case: true
|
map-underscore-to-camel-case: true
|
||||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||||
|
|
||||||
file:
|
upload:
|
||||||
path: ???
|
base-path: D:/stl-static
|
||||||
|
image:
|
||||||
|
coach: /images/coach/
|
||||||
|
member: /imges/member/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue