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);
|
}
|
|
}
|