myjf007
2024-11-04 627b61d17da1dbf02c0363c659b728627dd42890
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
package com.nova.sankuai.controller.v1;
 
 
import com.nova.sankuai.domain.entity.AppLoadConfig;
import com.nova.sankuai.infra.config.CommonException;
import com.nova.sankuai.infra.utils.ImageUtil;
import com.nova.sankuai.infra.utils.ResultJson;
import com.nova.sankuai.service.IAppLoadConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.annotation.Resource;
import java.util.List;
 
@Api(tags = "App载入页配置")
@RestController
@RequestMapping(value = "/api/v1/appLoadConfig")
public class AppLoadConfigController {
 
    @Resource
    private ImageUtil imageUtil;
    @Resource
    private IAppLoadConfigService appLoadConfigService;
 
    @ApiOperation(value = "载入页配置信息列表")
    @GetMapping("/list")
    public ResultJson<List<AppLoadConfig>> list(){
        List<AppLoadConfig> list = appLoadConfigService.list();
        return ResultJson.ok(list);
    }
    @ApiOperation(value = "新增配置页信息")
    @PostMapping("/add")
    public ResultJson<?> add(@RequestBody AppLoadConfig appLoadConfig){
        appLoadConfigService.save(appLoadConfig);
        return ResultJson.success();
    }
    @ApiOperation(value = "编辑配置页信息")
    @PostMapping("/edit")
    public ResultJson<?> edit(@RequestBody AppLoadConfig appLoadConfig){
        appLoadConfigService.updateById(appLoadConfig);
        return ResultJson.success();
    }
    @ApiOperation(value = "删除配置页信息")
    @GetMapping("/del")
    public ResultJson<?> del(@RequestParam Long id){
        appLoadConfigService.removeById(id);
        return ResultJson.success();
    }
 
    @ApiOperation(value = "获取app载入页配置")
    @GetMapping("/getAppLoadConfigById")
    public ResultJson<AppLoadConfig> getAppLoadConfigById(@RequestParam Integer id){
        AppLoadConfig loadConfig = appLoadConfigService.getById(id);
        return ResultJson.ok(loadConfig);
    }
    @ApiOperation(value = "上传加载页图片")
    @PostMapping("/uploadImage")
    public ResultJson<String> uploadImage(@RequestBody MultipartFile file) {
        String fame = "";
        Long len = file.getSize();
        boolean isBig = ImageUtil.checkFileSize(len, 5);
        if (!isBig) {
            throw new CommonException("文件不能超过5MB");
        }
        try {
            if (file.getSize() != 0) {
                fame = imageUtil.uploadFile(file, true);
            }
        } catch (Exception e) {
            throw new CommonException("upload fail");
        }
        return ResultJson.ok(fame);
    }
 
}