xiangpei
2024-05-31 16d10cef208de048f8b325facd143c54b7be9963
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.ycl.jxkg.controller.admin;
 
 
import com.ycl.jxkg.base.BaseApiController;
import com.ycl.jxkg.base.Result;
import com.ycl.jxkg.domain.Subject;
import com.ycl.jxkg.service.SubjectService;
import com.ycl.jxkg.utils.PageInfoHelper;
import com.ycl.jxkg.vo.admin.education.SubjectEditRequestVO;
import com.ycl.jxkg.vo.admin.education.SubjectPageRequestVO;
import com.ycl.jxkg.vo.admin.education.SubjectResponseVO;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import java.util.List;
 
@RestController("AdminEducationController")
@RequestMapping(value = "/api/admin/education")
public class EducationController extends BaseApiController {
 
    private final SubjectService subjectService;
 
    @Autowired
    public EducationController(SubjectService subjectService) {
        this.subjectService = subjectService;
    }
 
    @RequestMapping(value = "/subject/list", method = RequestMethod.POST)
    public Result<List<Subject>> list() {
        List<Subject> subjects = subjectService.allSubject();
        return Result.ok(subjects);
    }
 
    @RequestMapping(value = "/subject/page", method = RequestMethod.POST)
    public Result<PageInfo<SubjectResponseVO>> pageList(@RequestBody SubjectPageRequestVO model) {
        PageInfo<Subject> pageInfo = subjectService.page(model);
        PageInfo<SubjectResponseVO> page = PageInfoHelper.copyMap(pageInfo, e -> {
            SubjectResponseVO vo = new SubjectResponseVO();
            BeanUtils.copyProperties(e, vo);
            return vo;
        });
        return Result.ok(page);
    }
 
    @RequestMapping(value = "/subject/edit", method = RequestMethod.POST)
    public Result edit(@RequestBody @Valid SubjectEditRequestVO model) {
        Subject subject = new Subject();
        BeanUtils.copyProperties(model, subject);
        if (model.getId() == null) {
            subject.setDeleted(false);
            subjectService.insertByFilter(subject);
        } else {
            subjectService.updateByIdFilter(subject);
        }
        return Result.ok();
    }
 
    @RequestMapping(value = "/subject/select/{id}", method = RequestMethod.POST)
    public Result<SubjectEditRequestVO> select(@PathVariable Integer id) {
        Subject subject = subjectService.selectById(id);
        SubjectEditRequestVO vo = new SubjectEditRequestVO();
        BeanUtils.copyProperties(subject, vo);
        return Result.ok(vo);
    }
 
    @RequestMapping(value = "/subject/delete/{id}", method = RequestMethod.POST)
    public Result delete(@PathVariable Integer id) {
        Subject subject = subjectService.selectById(id);
        subject.setDeleted(true);
        subjectService.updateByIdFilter(subject);
        return Result.ok();
    }
}