Helius
2021-06-16 5728be2af515b2200e782aa201ca5d4d67d9ea47
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
package com.ibeetl.admin.console.web;
 
import com.ibeetl.admin.console.model.BannerModel;
import com.ibeetl.admin.console.model.ItemModel;
import com.ibeetl.admin.console.model.StorageModel;
import com.ibeetl.admin.console.service.RedisService;
import com.ibeetl.admin.console.service.SettingConsoleService;
import com.ibeetl.admin.console.util.PreventManyCommit;
import com.ibeetl.admin.console.web.query.SettingMoneyQuery;
import com.ibeetl.admin.core.annotation.Function;
import com.ibeetl.admin.core.entity.CoreSetMoney;
import com.ibeetl.admin.core.web.JsonResult;
import org.beetl.sql.core.engine.PageQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
 
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
 
/**
 * 设置选项
 */
@Controller
@Configuration
public class SettingController {
 
    private static final String MODEL = "/admin/setting";
    private final Logger log = LoggerFactory.getLogger(this.getClass());
 
    @Value("${file.upload.path}")
    String filePath;
 
    @Value("${file.address}")
    String fileAddress;
 
    @Autowired
    SettingConsoleService settingConsoleService;
 
 
    // 金额设置开始
    @GetMapping(MODEL + "/money/index.do")
    @Function("setting.money")
    ModelAndView index(){
        ModelAndView view = new ModelAndView("/admin/setting/moneySetIndex.html");
        return view;
    }
 
    @RequestMapping(MODEL + "/money/list.json")
    @Function("setting.money")
    @ResponseBody
    JsonResult<PageQuery<CoreSetMoney>> list(SettingMoneyQuery condtion){
        PageQuery<CoreSetMoney> page = condtion.getPageQuery();
        settingConsoleService.queryByCondtion(page);
        return JsonResult.success(page);
    }
 
    @PostMapping(MODEL + "/money/updateMoney.json")
    @Function("setting.money")
    @ResponseBody
    @PreventManyCommit(time = 10)
    JsonResult updateMoney(CoreSetMoney coreSetMoney){
        settingConsoleService.updateMoney(coreSetMoney);
        return JsonResult.success(null);
    }
    // 金额设置结束
 
    // 物品分类设置开始
    // 首页
    @GetMapping(MODEL + "/item/index.do")
    @Function("setting.item")
    ModelAndView itemIndex(){
        ModelAndView view = new ModelAndView("/admin/setting/itemSetting/index.html");
        return view;
    }
    // 编辑页
    @GetMapping(MODEL + "/item/edit.do")
    @Function("setting.item")
    ModelAndView editIndex(String id, @RequestParam(required = false) String parentId){
        ModelAndView view = new ModelAndView("/admin/setting/itemSetting/edit.html");
        view.addObject("id", id);
        view.addObject("parentId", parentId);
        return view;
    }
    // 添加页
    @GetMapping(MODEL + "/item/add.do")
    @Function("setting.item")
    ModelAndView addIndex(){
        ModelAndView view = new ModelAndView("/admin/setting/itemSetting/add.html");
        return view;
    }
    // 子类页
    @GetMapping(MODEL + "/item/child.do")
    @Function("setting.item")
    ModelAndView childIndex(String parentId){
        ModelAndView view = new ModelAndView("/admin/setting/itemSetting/child.html");
        view.addObject("parentId", parentId);
        return view;
    }
 
    /**
     * 查询
     * @param item
     * @return
     */
    @PostMapping(MODEL + "/item/querIteml.json")
    @Function("setting.item")
    @ResponseBody
    Map<String, Object> querIteml(ItemModel item){
        updateItemForRedis();
        return settingConsoleService.querIteml(item);
    }
 
    /**
     * 插入
     * @param item
     * @return
     */
    @PostMapping(MODEL + "/item/insertItem.json")
    @Function("setting.item")
    @PreventManyCommit(time = 10)
    @ResponseBody
    int insertItem(ItemModel item){
        return settingConsoleService.insertItem(item);
    }
 
    /**
     * 删除
     * @param item
     * @return
     */
    @PostMapping(MODEL + "/item/delItem.json")
    @Function("setting.item")
    @PreventManyCommit(time = 10)
    @ResponseBody
    int delItem(ItemModel item){
        return settingConsoleService.delItem(item);
    }
 
    /**
     * 更新
     * @param item
     * @return
     */
    @PostMapping(MODEL + "/item/updateItem.json")
    @Function("setting.item")
    @ResponseBody
    @PreventManyCommit(time = 10)
    int updateItem(ItemModel item){
        return settingConsoleService.updateItem(item);
    }
 
    /**
     * 更新redis里面的缓存
     */
    void updateItemForRedis(){
        settingConsoleService.updateItemForRedis();
    }
    // 物品设置结束
 
    /**
    文件上传
     */
    @PostMapping(MODEL + "/item/uploadAvatar.json")
    @Function("setting.item")
    @PreventManyCommit(time = 10)
    @ResponseBody
    Map<String, Object> uploadAvatar(@PathVariable MultipartFile file){
        if(file.isEmpty()){
            return null;
        }
        //文件名
        String fileName = file.getOriginalFilename();
        //后缀名
        String suffixName = fileName.substring(fileName.lastIndexOf("."));
        //图片名
        //String path = "/resource/static/img"; //文件存储位置  我放在了我的项目下
        fileName=UUID.randomUUID()+suffixName;
        File dest = new File(filePath+fileName);
        //File dest = new File(path+"\\"+fileName);
        if (!dest.getParentFile().exists()) {
            dest.getParentFile().mkdirs();
        }
        try {
            file.transferTo(dest);
            String url=fileAddress+fileName;
            //String url=address+"\\"+fileName;
            Map map=new HashMap();
            map.put("path",url);
            return map;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
 
 
    // --------仓库管理------------------------------------------------
 
    @GetMapping(MODEL + "/storage/index.do")
    @Function("storage")
    ModelAndView storageIndex(){
        return new ModelAndView("/admin/setting/storage/index.html");
    }
    @GetMapping(MODEL + "/storage/add.do")
    @Function("storage")
    ModelAndView addx(){
        return new ModelAndView("/admin/setting/storage/add.html");
    }
    /**
     * 查询仓库列表
     * @param storageModel
     * @return
     */
    @PostMapping(MODEL + "/storage/queryStorageList.json")
    @Function("storage")
    @ResponseBody
    Map<String, Object> queryStorageList(StorageModel storageModel){
        return settingConsoleService.queryStorageList(storageModel);
    }
 
    /**
     * 添加仓库
     * @param storageModel
     * @return
     */
    @PostMapping(MODEL + "/storage/addStorage.json")
    @Function("storage")
    @ResponseBody
    int addStorage(StorageModel storageModel){
        return settingConsoleService.addStorage(storageModel);
    }
 
    /**
     * 更新仓库
     * @param storageModel
     * @return
     */
    @PostMapping(MODEL + "/storage/updateStorage.json")
    @Function("storage")
    @ResponseBody
    int updateStorage(StorageModel storageModel){
        return settingConsoleService.updateStorage(storageModel);
    }
 
    /**
     * 删除仓库
     * @param storageModel
     * @return
     */
    @PostMapping(MODEL + "/storage/delStorage.json")
    @Function("storage")
    @ResponseBody
    int delStorage(StorageModel storageModel){
        return settingConsoleService.delStorage(storageModel);
    }
 
 
    // --banner管理----------------------------------------------
 
    @GetMapping(MODEL + "/banner/index.do")
    @Function("banner")
    ModelAndView bannerIndex(){
        return new ModelAndView("/admin/setting/banner/index.html");
    }
    @GetMapping(MODEL + "/banner/add.do")
    @Function("banner")
    ModelAndView bannerAdd(){
        return new ModelAndView("/admin/setting/banner/add.html");
    }
    @GetMapping(MODEL + "/banner/edit.do")
    @Function("banner")
    ModelAndView bannerEdit(BannerModel bannerModel){
        System.out.println(bannerModel.toString());
        ModelAndView view = new ModelAndView("/admin/setting/banner/edit.html");
        if(null!=bannerModel&&null!=bannerModel.getPicPath()){
            bannerModel.setPicPath("/");
            view.addObject("banner", bannerModel);
 
        }else{
            view.addObject("banner", bannerModel);
 
        }
        return view;
    }
 
    /**
     * 查询
     * @param bannerModel
     * @return
     */
    @PostMapping(MODEL + "/banner/queryBannerList.json")
    @Function("banner")
    @ResponseBody
    Map<String, Object> queryBannerList(BannerModel bannerModel){
        return settingConsoleService.queryBannerList(bannerModel);
    }
 
    /**
     * 添加
     * @param bannerModel
     * @return
     */
    @PostMapping(MODEL + "/banner/insertBanner.json")
    @Function("banner")
    @ResponseBody
    JsonResult insertBanner(BannerModel bannerModel){
        return settingConsoleService.insertBanner(bannerModel);
 
    }
 
    /**
     * 更新
     * @param bannerModel
     * @return
     */
    int updateBanner(BannerModel bannerModel){
        return settingConsoleService.updateBanner(bannerModel);
    }
 
    /**
     * 删除
     * @param id
     * @return
     */
    @PostMapping(MODEL + "/banner/delBanner.json")
    @Function("banner")
    @ResponseBody
    int delBanner(String id){
        return settingConsoleService.delBanner(id);
    }
 
}