mirror of
https://github.com/suyiiyii/SIMS.git
synced 2025-06-02 00:16:11 +08:00
实现记录的增加和删除
This commit is contained in:
parent
b8b14f7af9
commit
df4230a5d2
@ -3,10 +3,7 @@ package top.suyiiyii.sims.controller;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import top.suyiiyii.sims.common.AuthAccess;
|
import top.suyiiyii.sims.common.AuthAccess;
|
||||||
import top.suyiiyii.sims.common.Result;
|
import top.suyiiyii.sims.common.Result;
|
||||||
import top.suyiiyii.sims.entity.RewardPunishmentCategory;
|
import top.suyiiyii.sims.entity.RewardPunishmentCategory;
|
||||||
@ -20,8 +17,9 @@ public class CategoryController {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
CategoryService categoryService;
|
CategoryService categoryService;
|
||||||
|
|
||||||
@GetMapping("")
|
@GetMapping("")
|
||||||
@Operation(summary = "获取所有类别信息,支持分页")
|
@Operation(summary = "获取所有类别",description = "获取所有类别信息,支持分页")
|
||||||
@AuthAccess(allowRoles = {"admin"})
|
@AuthAccess(allowRoles = {"admin"})
|
||||||
public Result<List<RewardPunishmentCategory>> getAllCategory(
|
public Result<List<RewardPunishmentCategory>> getAllCategory(
|
||||||
@RequestParam(value = "page", defaultValue = "1") Integer page,
|
@RequestParam(value = "page", defaultValue = "1") Integer page,
|
||||||
@ -31,4 +29,32 @@ public class CategoryController {
|
|||||||
return Result.success(categoryService.getCateGory(pageObj));
|
return Result.success(categoryService.getCateGory(pageObj));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("")
|
||||||
|
@Operation(summary = "添加类别")
|
||||||
|
@AuthAccess(allowRoles = {"admin"})
|
||||||
|
public Result<String> addCategory(@RequestBody RewardPunishmentCategory category) {
|
||||||
|
category.setId(null);
|
||||||
|
categoryService.addCategory(category);
|
||||||
|
return Result.success("添加成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
@Operation(summary = "更新类别",description = """
|
||||||
|
根据id更新类别信息\n当status为"disable"时,表示禁用该类别\n当status为null或"enable"时,表示启用该类别""")
|
||||||
|
@AuthAccess(allowRoles = {"admin"})
|
||||||
|
public Result<String> updateCategory(@RequestBody RewardPunishmentCategory category,@PathVariable Integer id) {
|
||||||
|
category.setId(id);
|
||||||
|
category.setCategoryId(id);
|
||||||
|
categoryService.updateCategory(category);
|
||||||
|
return Result.success("更新成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
@Operation(summary = "删除类别",description = "根据id删除类别")
|
||||||
|
@AuthAccess(allowRoles = {"admin"})
|
||||||
|
public Result<String> deleteCategory(@PathVariable Integer id) {
|
||||||
|
categoryService.deleteCategory(id);
|
||||||
|
return Result.success("删除成功");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import top.suyiiyii.sims.entity.RewardPunishmentCategory;
|
import top.suyiiyii.sims.entity.RewardPunishmentCategory;
|
||||||
|
import top.suyiiyii.sims.exception.ServiceException;
|
||||||
import top.suyiiyii.sims.mapper.CategoryMapper;
|
import top.suyiiyii.sims.mapper.CategoryMapper;
|
||||||
import top.suyiiyii.sims.mapper.MpCategoryMapper;
|
import top.suyiiyii.sims.mapper.MpCategoryMapper;
|
||||||
|
|
||||||
@ -50,4 +51,26 @@ public class CategoryService {
|
|||||||
return mpCategoryMapper.selectBatchIds(ids);
|
return mpCategoryMapper.selectBatchIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateCategory(RewardPunishmentCategory category) {
|
||||||
|
if (!mpCategoryMapper.exists(new LambdaQueryWrapper<RewardPunishmentCategory>().eq(RewardPunishmentCategory::getId, category.getId()))) {
|
||||||
|
throw new ServiceException("该类别不存在");
|
||||||
|
}
|
||||||
|
RewardPunishmentCategory cateInDb = mpCategoryMapper.selectById(category.getId());
|
||||||
|
category.setId(cateInDb.getId());
|
||||||
|
category.setCategoryId(cateInDb.getCategoryId());
|
||||||
|
mpCategoryMapper.updateById(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addCategory(RewardPunishmentCategory category) {
|
||||||
|
mpCategoryMapper.insert(category);
|
||||||
|
category.setCategoryId(category.getId());
|
||||||
|
mpCategoryMapper.updateById(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteCategory(Integer id) {
|
||||||
|
if (!mpCategoryMapper.exists(new LambdaQueryWrapper<RewardPunishmentCategory>().eq(RewardPunishmentCategory::getId, id))) {
|
||||||
|
throw new ServiceException("该类别不存在");
|
||||||
|
}
|
||||||
|
mpCategoryMapper.deleteById(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ public class RecordService {
|
|||||||
List<Integer> catIds = recordDtos.stream().map(RecordDto::getCategoryId).distinct().toList();
|
List<Integer> catIds = recordDtos.stream().map(RecordDto::getCategoryId).distinct().toList();
|
||||||
List<RewardPunishmentCategory> categories = mpCategoryMapper.selectBatchIds(catIds);
|
List<RewardPunishmentCategory> categories = mpCategoryMapper.selectBatchIds(catIds);
|
||||||
Map<Integer, RewardPunishmentCategory> catMap = categories.stream().collect(Collectors.toMap(RewardPunishmentCategory::getId, c -> c));
|
Map<Integer, RewardPunishmentCategory> catMap = categories.stream().collect(Collectors.toMap(RewardPunishmentCategory::getId, c -> c));
|
||||||
List<Integer> availableCatIds = catIds.stream().filter(c -> (catMap.containsKey(c) && catMap.get(c).getStatus() == null)).toList();
|
List<Integer> availableCatIds = catIds.stream().filter(c -> (catMap.containsKey(c) && (catMap.get(c).getStatus() == null || catMap.get(c).getStatus().equals("enable")))).toList();
|
||||||
return recordDtos.stream().filter(r -> availableCatIds.contains(r.getCategoryId())).toList();
|
return recordDtos.stream().filter(r -> availableCatIds.contains(r.getCategoryId())).toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user