mirror of
				https://github.com/suyiiyii/SIMS.git
				synced 2025-11-04 15:54:52 +08:00 
			
		
		
		
	实现记录的替换
This commit is contained in:
		
							parent
							
								
									df4230a5d2
								
							
						
					
					
						commit
						ec0c8b20ce
					
				@ -52,8 +52,9 @@ public class CategoryController {
 | 
			
		||||
    @DeleteMapping("/{id}")
 | 
			
		||||
    @Operation(summary = "删除类别",description = "根据id删除类别")
 | 
			
		||||
    @AuthAccess(allowRoles = {"admin"})
 | 
			
		||||
    public Result<String> deleteCategory(@PathVariable Integer id) {
 | 
			
		||||
        categoryService.deleteCategory(id);
 | 
			
		||||
    public Result<String> deleteCategory(@PathVariable Integer id,
 | 
			
		||||
                                         @RequestParam Integer newId) {
 | 
			
		||||
        categoryService.deleteCategory(id, newId);
 | 
			
		||||
        return Result.success("删除成功");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,7 @@
 | 
			
		||||
package top.suyiiyii.sims.mapper;
 | 
			
		||||
 | 
			
		||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 | 
			
		||||
import top.suyiiyii.sims.entity.Record;
 | 
			
		||||
 | 
			
		||||
public interface MpRecordMapper extends BaseMapper<Record> {
 | 
			
		||||
}
 | 
			
		||||
@ -1,13 +1,16 @@
 | 
			
		||||
package top.suyiiyii.sims.service;
 | 
			
		||||
 | 
			
		||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
			
		||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 | 
			
		||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import top.suyiiyii.sims.entity.Record;
 | 
			
		||||
import top.suyiiyii.sims.entity.RewardPunishmentCategory;
 | 
			
		||||
import top.suyiiyii.sims.exception.ServiceException;
 | 
			
		||||
import top.suyiiyii.sims.mapper.CategoryMapper;
 | 
			
		||||
import top.suyiiyii.sims.mapper.MpCategoryMapper;
 | 
			
		||||
import top.suyiiyii.sims.mapper.MpRecordMapper;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
@ -27,6 +30,9 @@ public class CategoryService {
 | 
			
		||||
    @Autowired
 | 
			
		||||
    MpCategoryMapper mpCategoryMapper;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    MpRecordMapper mpRecordMapper;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public String getCategoryName(Integer id) {
 | 
			
		||||
        return categoryMapper.getCategoryName(id);
 | 
			
		||||
@ -67,10 +73,11 @@ public class CategoryService {
 | 
			
		||||
        mpCategoryMapper.updateById(category);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void deleteCategory(Integer id) {
 | 
			
		||||
    public void deleteCategory(Integer id, Integer newId) {
 | 
			
		||||
        if (!mpCategoryMapper.exists(new LambdaQueryWrapper<RewardPunishmentCategory>().eq(RewardPunishmentCategory::getId, id))) {
 | 
			
		||||
            throw new ServiceException("该类别不存在");
 | 
			
		||||
        }
 | 
			
		||||
        mpCategoryMapper.deleteById(id);
 | 
			
		||||
        mpRecordMapper.update(new LambdaUpdateWrapper<Record>().eq(Record::getCategoryId, id).set(Record::getCategoryId, newId));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user