SysFileController.java 1.92 KB
package com.glsx.smart.controller;

import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.core.web.R;
import com.glsx.smart.pojo.FileDTO;
import com.glsx.smart.service.SmartSysFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>Description:
 * <p>Project: chejia-smart
 *
 * @author wbh
 * @date 2021-03-15
 */
@Slf4j
@RestController
@RequestMapping("/sysFile")
@Api(value = "图片管理", tags = {"图片管理"})
public class SysFileController {

    @Autowired
    private SmartSysFileService sysFileService;

    @RequestMapping(value = "/findAll", method = {RequestMethod.GET})
    @ApiOperation(value = "查询图片")
    public R findAll(@RequestParam("type") String type) {
        List<FileDTO> fileDTOS = sysFileService.findByType(type);
        return R.ok(JSONObject.toJSONString(fileDTOS));
    }

    @RequestMapping(value = "/saveFile", method = {RequestMethod.POST})
    @ApiOperation(value = "保存图片")
    public R saveFile(@RequestBody List<FileDTO> files) {
        try {
            sysFileService.saveFile(files);
        } catch (Exception e) {
            return R.error();
        }
        return R.ok();
    }

    @RequestMapping(value = "/updateFile", method = {RequestMethod.POST})
    @ApiOperation(value = "更新图片")
    public R updateFile(@RequestBody FileDTO fileDTO) {
        try {
            sysFileService.updateFile(fileDTO);
        } catch (Exception e) {
            return R.error();
        }
        return R.ok();
    }
}