|
|
@ -0,0 +1,104 @@ |
|
|
|
package com.lottery.admin.controller; |
|
|
|
|
|
|
|
import com.lottery.admin.mapper.AdminGradeMapper; |
|
|
|
import com.lottery.admin.service.AdminGradeService; |
|
|
|
import com.lottery.dto.GradeDto; |
|
|
|
import com.lottery.entity.Grade; |
|
|
|
import com.lottery.exception.SomeException; |
|
|
|
import com.lottery.result.Result; |
|
|
|
import com.lottery.utils.ConvertBeanUtil; |
|
|
|
import com.lottery.vo.GradeVo; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
|
* @program: lottery-system |
|
|
|
* @ClassName GradeController |
|
|
|
* @description: |
|
|
|
* @author: wwl |
|
|
|
* @create: 2025-07-14 14:44 |
|
|
|
* @Version 1.0 |
|
|
|
**/ |
|
|
|
@RestController |
|
|
|
@RequestMapping("/admin/grade") |
|
|
|
public class AdminGradeController { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private AdminGradeService adminGradeService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private AdminGradeMapper adminGradeMapper; |
|
|
|
|
|
|
|
private final static Logger LOGGER = LoggerFactory.getLogger(AdminGradeController.class); |
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/list") |
|
|
|
public Result<List<GradeVo>> selectGrade(){ |
|
|
|
LOGGER.info("查询所有等级"); |
|
|
|
return Result.success(ConvertBeanUtil.convertList(adminGradeService.list(), GradeVo.class)); |
|
|
|
} |
|
|
|
|
|
|
|
@GetMapping("/details") |
|
|
|
public Result<GradeVo> selectById(@RequestParam Long id){ |
|
|
|
LOGGER.info("根据id查找等级:{}",id); |
|
|
|
return Result.success(ConvertBeanUtil.convert(adminGradeService.getById(id), GradeVo.class)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/add") |
|
|
|
public Result add(@RequestBody GradeDto gradeDto){ |
|
|
|
|
|
|
|
LOGGER.info("新增等级:{}", gradeDto); |
|
|
|
if (gradeDto.getGradeName() == null || gradeDto.getAmount() == null|| |
|
|
|
gradeDto.getSort() == null || gradeDto.getPerWin() == null) { |
|
|
|
return Result.failure("所有字段都必须填写"); |
|
|
|
} |
|
|
|
|
|
|
|
Grade grade = ConvertBeanUtil.convert(gradeDto, Grade.class); |
|
|
|
|
|
|
|
grade.setCreateTime(new Date()); |
|
|
|
grade.setUpdateTime(new Date()); |
|
|
|
|
|
|
|
if (!adminGradeService.save(grade)) return Result.failure("新增失败"); |
|
|
|
|
|
|
|
return Result.success(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PutMapping("/update") |
|
|
|
public Result update(@RequestBody GradeDto gradeDto){ |
|
|
|
|
|
|
|
if (gradeDto.getGradeName() == null || gradeDto.getAmount() == null|| |
|
|
|
gradeDto.getSort() == null || gradeDto.getPerWin() == null) { |
|
|
|
return Result.failure("所有字段都必须填写"); |
|
|
|
} |
|
|
|
|
|
|
|
LOGGER.info("修改等级:{}", gradeDto); |
|
|
|
if (adminGradeService.getById(gradeDto.getId())== null) { |
|
|
|
return Result.failure("修改的id不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
Grade grade = ConvertBeanUtil.convert(gradeDto, Grade.class); |
|
|
|
grade.setUpdateTime(new Date()); |
|
|
|
|
|
|
|
if (!adminGradeService.updateById(grade)) return Result.failure("修改失败"); |
|
|
|
return Result.success(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@DeleteMapping("/delete") |
|
|
|
public Result delete(@RequestParam Long id){ |
|
|
|
LOGGER.info("删除id为:{} 的等级" ,id); |
|
|
|
if (!adminGradeService.removeById(id)){ |
|
|
|
return Result.failure("删除失败"); |
|
|
|
} |
|
|
|
return Result.success(); |
|
|
|
} |
|
|
|
|
|
|
|
} |