baizonghao
2023-07-31 98b2f41e13c48219e054cf8b80c459298a01c910
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
package com.mindskip.xzs.controller.admin;
 
import com.github.pagehelper.PageInfo;
import com.mindskip.xzs.base.BaseApiController;
import com.mindskip.xzs.base.RestResponse;
import com.mindskip.xzs.domain.Department;
import com.mindskip.xzs.service.DepartmentService;
import com.mindskip.xzs.utility.PageInfoHelper;
import com.mindskip.xzs.viewmodel.department.DepartmentResponseVM;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import java.util.List;
 
 
@RestController("AdminDepartmentController")
@RequestMapping("/api/admin/department")
public class DepartmentController extends BaseApiController {
 
 
    private final DepartmentService departmentService;
 
    @Autowired
    public DepartmentController(DepartmentService departmentService) {
        this.departmentService = departmentService;
    }
 
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public RestResponse<List<Department>> getAll(){
        List<Department> res = departmentService.gets();
        return RestResponse.ok(res);
    }
 
 
    @RequestMapping(value = "/page/list", method = RequestMethod.POST)
    public RestResponse<PageInfo<DepartmentResponseVM>> pageList(@RequestBody DepartmentResponseVM model) {
        PageInfo<Department> pageInfo = departmentService.gets(model);
        PageInfo<DepartmentResponseVM> page = PageInfoHelper.copyMap(pageInfo, q -> {
            DepartmentResponseVM vm = modelMapper.map(q,DepartmentResponseVM.class);
            return vm;
        });
        return RestResponse.ok(page);
    }
 
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public RestResponse add(@RequestBody @Valid String  name) {
        return RestResponse.ok(departmentService.add(name));
    }
 
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public RestResponse update(@RequestBody @Valid Department  model) {
        return RestResponse.ok(departmentService.update(model));
    }
 
    @RequestMapping(value = "/get/{id}", method = RequestMethod.POST)
    public RestResponse update(@PathVariable Integer id) {
        return RestResponse.ok(departmentService.getById(id));
    }
}