zhangf
2024-08-08 71706ced3375f4c18148516d0477d8fd645de2ee
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
package com.gkhy.huataiFourierSpecialGasMonitor.controller;
 
import com.gkhy.huataiFourierSpecialGasMonitor.annotation.RepeatedClick;
import com.gkhy.huataiFourierSpecialGasMonitor.api.controller.common.BaseController;
import com.gkhy.huataiFourierSpecialGasMonitor.commons.domain.Result;
import com.gkhy.huataiFourierSpecialGasMonitor.commons.enums.SystemCacheKeyEnum;
import com.gkhy.huataiFourierSpecialGasMonitor.commons.model.PageQuery;
import com.gkhy.huataiFourierSpecialGasMonitor.entity.query.FindGasCategoryPageQuery;
import com.gkhy.huataiFourierSpecialGasMonitor.entity.req.CreateGasCategoryReqDTO;
import com.gkhy.huataiFourierSpecialGasMonitor.entity.req.UpdateGasCategoryReqDTO;
import com.gkhy.huataiFourierSpecialGasMonitor.service.GasCategoryService;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.PostConstruct;
 
@RestController
@RequestMapping("/gasCategory")
public class GasCategoryController extends BaseController {
 
    @Autowired
    private GasCategoryService gasCategoryService;
 
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
    @Autowired
    private RedissonClient redissonClient;
 
    /**
     * @decription 新增气体
     * @author Mr.huang
     */
    @PostMapping("/add")
    @RepeatedClick
    public Result createGasCategory(@RequestBody CreateGasCategoryReqDTO reqDto){
        Result result = gasCategoryService.createGasCategory(reqDto);
        return result;
    }
 
    /**
     * @decription 更新气体
     * @author Mr.huang
     */
    @PostMapping("/update")
    @RepeatedClick
    public Result updateGasCategory(@RequestBody UpdateGasCategoryReqDTO reqDto){
        Result result = gasCategoryService.updateGasCategory(reqDto);
        return result;
    }
 
 
    @GetMapping("/findById")
    public Result findGasCategoryById(@RequestParam Integer id){
        Result result = gasCategoryService.findGasCategoryById(id);
        return result;
    }
 
    @PostMapping("/page")
    public Result findGasCategoryPage(@RequestBody PageQuery<FindGasCategoryPageQuery> pageQuery){
        Result result = gasCategoryService.findGasCategoryPage(pageQuery);
        return result;
    }
 
    @PostMapping("/list")
    public Result gasCategoryList(){
        Result result = gasCategoryService.gasCategoryList();
        return result;
    }
 
    @PostConstruct
    private void gasCategoryListCache(){
        //清除redis缓存
        RBucket<Object> bucket = redissonClient.getBucket(SystemCacheKeyEnum.KEY_GAS_CATEGORY.getKey());
        if (bucket.isExists()) {
            bucket.delete();
        }
        this.gasCategoryList();
        logger.info("[GasCategoryList] cache complete");
    }
 
}