jinpengyong
2023-12-08 7a9deef40c60e1b0614acb7cd215a12829a8476d
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
package com.moral.api.controller;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.Map;
 
import javax.validation.Valid;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.entity.Divisor;
import com.moral.api.mapper.DivisorMapper;
import com.moral.api.service.DivisorService;
import com.moral.constant.Constants;
import com.moral.constant.ResponseCodeEnum;
import com.moral.constant.ResultMessage;
 
/**
 * Description //todo
 *
 * @author swb
 * @ClassName DivisorController
 * @date 2023.12.06 14:15
 */
 
@Slf4j
@Api(tags = {"因子配置"})
@RestController
@RequestMapping(value = "/divisor")
public class DivisorController {
 
 
    @Autowired
    private DivisorService divisorService;
 
 
 
    @PostMapping("insert")
    @ApiOperation("新增")
    public ResultMessage  insert(@Valid @RequestBody Divisor divisor){
        QueryWrapper<Divisor> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("organization_id", divisor.getOrganizationId()).eq("is_del", Constants.NOT_DELETE);
        if (divisorService.getOne(queryWrapper) != null) {
            return ResultMessage.fail(ResponseCodeEnum.MAC_IS_EXIST.getCode(), ResponseCodeEnum.MAC_IS_EXIST.getMsg());
        }
        divisorService.insert(divisor);
        return ResultMessage.ok();
    }
 
 
    @PostMapping("update")
    @ApiOperation("修改")
    public ResultMessage  update(@Valid @RequestBody Divisor divisor){
 
        QueryWrapper<Divisor> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("organization_id", divisor.getOrganizationId()).eq("is_del", Constants.NOT_DELETE);
        if (divisorService.getOne(queryWrapper) != null) {
            return ResultMessage.fail(ResponseCodeEnum.MAC_IS_EXIST.getCode(), ResponseCodeEnum.MAC_IS_EXIST.getMsg());
        }
        divisorService.update(divisor);
        return ResultMessage.ok();
    }
 
    @GetMapping("delete")
    @ApiOperation("删除")
    public ResultMessage  delete(@RequestParam @ApiParam(value = "id",name = "主键id") Integer id){
        divisorService.delete(id);
        return ResultMessage.ok();
    }
 
 
 
    @GetMapping("select")
    @ApiOperation("详情")
    public ResultMessage  select(@RequestParam @ApiParam(value = "id",name = "主键id") Integer id){
        Divisor divisor = divisorService.queryById(id);
        return ResultMessage.ok(ObjectUtils.isEmpty(divisor)?"0":divisor);
    }
 
 
    @GetMapping("page")
    @ApiOperation("分页")
    public ResultMessage page(@RequestParam @ApiParam(value = "mac",name = "mac号") String mac,
                              @RequestParam @ApiParam(value = "page",name = "页码") String page,
                              @RequestParam @ApiParam(value = "size",name = "条数") String size) {
        Map<String, Object> select = divisorService.select(mac, page, size);
        return ResultMessage.ok(ObjectUtils.isEmpty(select)?"0":select);
    }
 
}