tj
2025-03-20 87a0ccb7ed3f0c9bfd856169ef03de136cd1047d
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package com.jsh.erp.controller;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.datasource.entities.SysDict;
import com.jsh.erp.dto.ConfigSecurityCreateOrUpdate;
import com.jsh.erp.dto.ConfigSecurityQuery;
import com.jsh.erp.datasource.entities.ConfigSecurity;
import com.jsh.erp.service.configSecurity.ConfigSecurityService;
import com.jsh.erp.utils.BaseResponseInfo;
import com.jsh.erp.utils.ErpInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
 
/**
 * @author ji sheng hua jshERP
 */
@RestController
@RequestMapping(value = "/config-security")
@Api(tags = {"高级安全防护管理"})
public class ConfigSecurityController {
    private Logger logger = LoggerFactory.getLogger(ConfigSecurityController.class);
 
    @Resource
    private ConfigSecurityService configSecurityService;
 
 
    /**
     * 高级安全防护列表
     * @param currentPage
     * @param pageSize
     * @param type
     * @param keyword
     * @param request
     * @return
     * @throws Exception
     */
//    @GetMapping(value = "/list")
//    @ApiOperation(value = "高级安全防护列表")
//    public BaseResponseInfo findAccountInOutList(@RequestParam("currentPage") Integer currentPage,
//                                                 @RequestParam("pageSize") Integer pageSize,
//                                                 @RequestParam(value = "type", required = false) String  type  ,
//                                                 @RequestParam(value = "keyword", required = false) String keyword,
//                                                 HttpServletRequest request) throws Exception{
//        ConfigSecurityQuery configSecurityQuery = new ConfigSecurityQuery(keyword,type, null, null, null, null);
//        configSecurityQuery.setCurrentPage(currentPage);
//        configSecurityQuery.setPageSize(pageSize);
//        BaseResponseInfo res = new BaseResponseInfo();
//        Map<String, Object> map = new HashMap<String, Object>();
//        try {
//            List<ConfigSecurity> dataList = configSecurityService.findList(configSecurityQuery);
//            Long total = configSecurityService.findListCount(configSecurityQuery);
//            map.put("total", total);
//            map.put("rows", dataList);
//            res.code = 200;
//            res.data = map;
//        } catch(Exception e){
//            logger.error(e.getMessage(), e);
//            res.code = 500;
//            res.data = "获取数据失败";
//        }
//        return res;
//    }
 
 
    @GetMapping(value = "/list")
    @ApiOperation(value = "高级安全防护列表")
    public BaseResponseInfo findAccountInOutList(ConfigSecurityQuery configSecurityQuery,
                                                 HttpServletRequest request) throws Exception{
        BaseResponseInfo res = new BaseResponseInfo();
        Map<String, Object> map = new HashMap<String, Object>();
        try {
            List<ConfigSecurity> dataList = configSecurityService.findList(configSecurityQuery);
            Long total = configSecurityService.findListCount(configSecurityQuery);
            map.put("total", total);
            map.put("rows", dataList);
            res.code = 200;
            res.data = map;
        } catch(Exception e){
            logger.error(e.getMessage(), e);
            res.code = 500;
            res.data = "获取数据失败";
        }
        return res;
    }
 
 
    @PostMapping
    public BaseResponseInfo add(@RequestBody @Valid ConfigSecurityCreateOrUpdate configSecurityCreateOrUpdate) {
        ConfigSecurity configSecurity = new ConfigSecurity();
        BeanUtils.copyProperties(configSecurityCreateOrUpdate, configSecurity);
        BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
        try {
            int result = configSecurityService.add(configSecurity);
            if(result > 0) {
                baseResponseInfo.code = 200;
                baseResponseInfo.msg = "新增成功";
            }
        } catch(Exception e) {
            baseResponseInfo.code = 500;
            baseResponseInfo.msg = e.getMessage();
        }
        return baseResponseInfo;
    }
 
    @PutMapping
    public BaseResponseInfo update(@RequestBody @Valid ConfigSecurityCreateOrUpdate configSecurityCreateOrUpdate) {
        ConfigSecurity configSecurity = new ConfigSecurity();
        BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
        try {
            int result = configSecurityService.update(configSecurity);
            if(result > 0) {
                baseResponseInfo.code = 200;
                baseResponseInfo.msg = "修改成功";
            }
        } catch(Exception e) {
            baseResponseInfo.code = 500;
            baseResponseInfo.msg = e.getMessage();
        }
        return baseResponseInfo;
    }
 
    @DeleteMapping("/delete/{id}")
    public BaseResponseInfo delete(@PathVariable Long id) {
        BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
        try {
            int result = configSecurityService.deleteById(id);
            if(result > 0) {
                baseResponseInfo.code = 200;
                baseResponseInfo.msg = "删除成功";
            }
        } catch(Exception e) {
            baseResponseInfo.code = 500;
            baseResponseInfo.msg = e.getMessage();
        }
        return baseResponseInfo;
    }
 
    @DeleteMapping("/deleteBatch")
    public BaseResponseInfo deleteBatch(@RequestParam("ids") String ids) {
        BaseResponseInfo baseResponseInfo = new BaseResponseInfo();
 
        try {
            int result= configSecurityService.deleteBatch(ids);
            if(result > 0) {
                baseResponseInfo.code = 200;
                baseResponseInfo.msg = "删除成功";
            }
        } catch(Exception e) {
            baseResponseInfo.code = 500;
            baseResponseInfo.msg = e.getMessage();
        }
        return baseResponseInfo;
    }
 
 
    /**
     * 批量设置状态-启用或者禁用
     * @param jsonObject
     * @param request
     * @return
     */
    @PostMapping(value = "/batchSetStatus")
    @ApiOperation(value = "批量设置状态")
    public String batchSetStatus(@RequestBody JSONObject jsonObject,
                                 HttpServletRequest request)throws Exception {
        Integer status = jsonObject.getInteger("status");
        String ids = jsonObject.getString("ids");
        Map<String, Object> objectMap = new HashMap<>();
        int res = configSecurityService.batchSetStatus(status, ids);
        if(res > 0) {
            return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
        } else {
            return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
        }
    }
}