zj
2024-06-03 5668aa7dc743d930b4b09dce1e7ccbba371e93cf
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
package org.example.ssmico.demos.web.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.example.ssmico.demos.web.entity.IcoOrder;
import org.example.ssmico.demos.web.entity.TConfiguration;
import org.example.ssmico.demos.web.service.TConfigurationService;
import org.example.ssmico.demos.web.util.ResultObject;
import org.example.ssmico.demos.web.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
 
import java.util.List;
 
/**
 * @program: ssm-ico
 * @description: 配置表
 * @create: 2024-04-15 11:11
 **/
@Controller
@RequestMapping({"/wap/api/tConfiguration"})
@CrossOrigin
public class TConfigurationController {
 
    @Autowired
    private TConfigurationService service;
 
    @ResponseBody
    @RequestMapping(value = "/add")
    public ServerResponse add(TConfiguration tConfiguration){
        try {
            long count = service.count(new LambdaQueryWrapper<TConfiguration>()
                    .eq(TConfiguration::getConfigKey, tConfiguration.getConfigKey()));
            if(count > 0){
                return ServerResponse.createByErrorMsg("当前配置key已存在");
            }
            service.save(tConfiguration);
            return ServerResponse.createBySuccess();
        }catch (Exception e){
            e.printStackTrace();
            return ServerResponse.createByErrorMsg("系统错误");
        }
    }
 
    @ResponseBody
    @RequestMapping(value = "/getPageList")
    public ServerResponse getPageList(String key,Integer pageNo,Integer size){
        try {
            if (null == pageNo || null == size) {
                pageNo = 1;
                size = 10;
            }
            // 创建分页对象
            Page<TConfiguration> page = new Page<>(pageNo, size);
            Page<TConfiguration> pageList = service.page(page, new LambdaQueryWrapper<TConfiguration>().like(!StringUtils.isBlank(key),TConfiguration::getConfigKey, key));
            return ServerResponse.createBySuccess(pageList);
        }catch (Exception e){
            e.printStackTrace();
            return ServerResponse.createByErrorMsg("系统错误");
        }
    }
 
    @ResponseBody
    @RequestMapping(value = "/update")
    public ServerResponse update(TConfiguration tConfiguration){
        try {
            long count = service.count(new LambdaQueryWrapper<TConfiguration>()
                    .eq(TConfiguration::getConfigKey, tConfiguration.getConfigKey())
                    .ne(TConfiguration::getId, tConfiguration.getId()));
            if(count > 0){
                return ServerResponse.createByErrorMsg("当前配置key已存在");
            }
            service.updateById(tConfiguration);
            return ServerResponse.createBySuccess();
        }catch (Exception e){
            e.printStackTrace();
            return ServerResponse.createByErrorMsg("系统错误");
        }
    }
 
    @ResponseBody
    @RequestMapping(value = "/delete")
    public ServerResponse delete(Integer id){
        try {
            service.removeById(id);
            return ServerResponse.createBySuccess();
        }catch (Exception e){
            e.printStackTrace();
            return ServerResponse.createByErrorMsg("系统错误");
        }
    }
 
    @ResponseBody
    @RequestMapping(value = "/getConfiguration")
    public ResultObject getConfiguration(){
        ResultObject resultObject=  new ResultObject();
        try {
            List<TConfiguration> list = service.list();
            resultObject.setData(list);
            return resultObject;
        }catch (Exception e){
            e.printStackTrace();
            resultObject.setCode("1");
            resultObject.setMsg("程序错误");
            return resultObject;
        }
    }
}