郑永安
2023-08-23 0a9ed7b7488de66a50799f79369d7806910ae00a
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package com.gk.hotwork.Controller;
 
import com.gk.hotwork.Controller.Base.BaseController;
import com.gk.hotwork.Domain.SpecialityInfo;
import com.gk.hotwork.Domain.Utils.Msg;
import com.gk.hotwork.Domain.Utils.PageInfo;
import com.gk.hotwork.Domain.Utils.StringUtils;
import com.gk.hotwork.Domain.dto.req.IdParam;
import com.gk.hotwork.Domain.dto.req.SpecialityAddReqDTO;
import com.gk.hotwork.Domain.dto.req.SpecialityModReqDTO;
import com.gk.hotwork.Service.SpecialityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.Date;
import java.util.HashMap;
import java.util.List;
 
/**
 * @email 1603559716@qq.com
 * @author: zf
 * @date: 2023/7/17
 * @time: 13:36
 */
@Api(tags = "专业接口")
@RequestMapping("/speciality")
@RestController
public class SpecialityController extends BaseController {
 
    @Autowired
    private SpecialityService specialityService;
 
    @PostMapping("/add")
    @ApiOperation(value = "添加专业数据",response = Msg.class)
    public Msg addSpeciality(@Validated @RequestBody SpecialityAddReqDTO specialityAddReqDTO){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        SpecialityInfo specialityInfo = new SpecialityInfo();
        specialityInfo.setName(specialityAddReqDTO.getName());
        specialityInfo.setRemark(specialityAddReqDTO.getRemark());
        specialityInfo.setIsDel((byte)0);
        specialityInfo.setCreateTime(new Date());
        specialityInfo.setCreateBy(getUser().getRealname());
        specialityInfo.setUpdateTime(new Date());
        specialityInfo.setUpdateBy(getUser().getRealname());
        specialityService.save(specialityInfo);
       return msg;
    }
 
    @PostMapping("/mod")
    @ApiOperation(value = "修改专业数据",response = Msg.class)
    public Msg modSpeciality(@Validated @RequestBody SpecialityModReqDTO specialityModReqDTO){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        SpecialityInfo specialityInfo = new SpecialityInfo();
        specialityInfo.setId(specialityModReqDTO.getId());
        specialityInfo.setName(specialityModReqDTO.getName());
        specialityInfo.setRemark(specialityModReqDTO.getRemark());
        specialityInfo.setUpdateTime(new Date());
        specialityInfo.setCreateBy(getUser().getRealname());
        specialityService.updateById(specialityInfo);
        return msg;
    }
 
    @PostMapping("/del")
    @ApiOperation(value = "删除专业数据",response = Msg.class)
    public Msg delSpeciality(@Validated @RequestBody IdParam idParam){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        SpecialityInfo specialityInfo = new SpecialityInfo();
        specialityInfo.setId(idParam.getId());
        specialityInfo.setIsDel((byte)1);
        specialityInfo.setUpdateTime(new Date());
        specialityInfo.setCreateBy(getUser().getRealname());
        specialityService.updateById(specialityInfo);
        return msg;
    }
 
    @GetMapping("/list/page")
    @ApiOperation(value = "分页查询专业数据",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "专业名称")
    })
    public Msg listSpecialityByPage(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize,String name){
 
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        PageInfo pageInfo = new PageInfo(pageIndex, pageSize);
        HashMap<String, Object> condition = new HashMap<String, Object>();
 
        if (StringUtils.isNotBlank(name)) {
            condition.put("name", name.trim());
        }
 
        pageInfo.setCondition(condition);
        specialityService.listSpecialityByPage(pageInfo);
        msg.setResult(pageInfo);
        return msg;
    }
 
    @GetMapping("/list")
    @ApiOperation(value = "专业数据列表",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "专业名称")
    })
    public Msg listSpeciality(String name){
 
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        List<SpecialityInfo> specialityInfos = specialityService.listSpeciality(name);
        msg.setResult(specialityInfos);
        return msg;
    }
 
 
}