feat: 添加教练退出/复职/新增功能,修复OGNL表达式语法错误
This commit is contained in:
parent
431ee1eb35
commit
ef18b12eb1
8 changed files with 140 additions and 19 deletions
|
|
@ -1,14 +1,13 @@
|
|||
package edu.situ.stlserver.controller;
|
||||
|
||||
|
||||
import edu.situ.stlserver.dao.CoachMapper;
|
||||
import edu.situ.stlserver.model.entity.Coach;
|
||||
import edu.situ.stlserver.model.dto.CoachAddDTO;
|
||||
import edu.situ.stlserver.model.dto.CoachQueryDTO;
|
||||
import edu.situ.stlserver.model.vo.HttpResult;
|
||||
import edu.situ.stlserver.service.CoachService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/coach")
|
||||
|
|
@ -19,8 +18,29 @@ public class CoachController {
|
|||
|
||||
|
||||
@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.query.CoachQuery;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
import edu.situ.stlserver.model.dto.CoachQueryDTO;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -32,8 +29,16 @@ public interface CoachMapper {
|
|||
"</where>",
|
||||
"</script>"
|
||||
})
|
||||
List<Coach> select(CoachQuery coachQuery);
|
||||
List<Coach> select(CoachQueryDTO coachQueryDTO);
|
||||
|
||||
@Update(value = "UPDATE `coaches` SET `quit_date` = #{quitDate} WHERE `id` = #{id}")
|
||||
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;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import edu.situ.stlserver.model.dto.CoachAddDTO;
|
||||
import edu.situ.stlserver.model.entity.Coach;
|
||||
import edu.situ.stlserver.model.dto.CoachQueryDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -9,5 +11,8 @@ import java.util.List;
|
|||
|
||||
public interface CoachService {
|
||||
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;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
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.service.CoachService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class CoachServiceImpl implements CoachService {
|
||||
|
||||
@Value("${upload.base-path}")
|
||||
private String baseUploadPath;
|
||||
@Value("${upload.image.coach}")
|
||||
private String coachUploadPath;
|
||||
|
||||
@Autowired
|
||||
private CoachMapper coachMapper;
|
||||
|
||||
|
|
@ -22,10 +34,53 @@ public class CoachServiceImpl implements CoachService {
|
|||
}
|
||||
|
||||
@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(limit == null) limit=10;
|
||||
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
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
file:
|
||||
path: ???
|
||||
upload:
|
||||
base-path: D:/stl-static
|
||||
image:
|
||||
coach: /images/coach/
|
||||
member: /imges/member/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue