package com.app.controller;

import com.app.annotation.platform.OperationLog;
import com.app.dto.CommonImgDto;
import com.app.dto.FileDto;
import com.app.dto.Result;
import com.app.util.file.FileUtil;
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.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Optional;

/**
 * 功能描述：账号
 *
 * @Auther: 梁展鹏
 * @Date: 2018/7/24 11:38
 */
@Api(description = "公用Api接口")
@Slf4j
@RestController
@RequestMapping("/common")
public class CommonController {

    @Autowired
    private FileUtil fileUtil;

    @OperationLog("更新 - 上传图片")
    @ApiOperation(value = "上传图片")
    @PostMapping("/upload")
    public ResponseEntity<Result> upload(@RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return new ResponseEntity(new Result().ok("文件为空"), HttpStatus.OK);
        }

        Optional<FileDto> dto = fileUtil.upload(file);
        if (dto.isPresent()) {
            return new ResponseEntity(new Result().ok(dto), HttpStatus.OK);
        } else {
            return new ResponseEntity(new Result().serverError(), HttpStatus.OK);
        }
    }

    @ApiOperation(value = "公共图片")
    @GetMapping("/img")
    public ResponseEntity<Result<CommonImgDto>> img() {
        CommonImgDto commonImgDto = new CommonImgDto();

        /* 乐伴430 */
//        commonImgDto.setWelcomeLogo("/file/32af5d6f-c177-4198-9e7a-30c7570ee6b9.png"); // 乐伴430
//        commonImgDto.setPayAgreement("/file/32af5d6f-c177-4198-9e7a-30c7570ee6b9.png");
//        commonImgDto.setAboutLogo("/file/32af5d6f-c177-4198-9e7a-30c7570ee6b9.png"); // 乐伴430

        /* 红英小学 */
//        commonImgDto.setWelcomeLogo("/file/e4cc3184-95e0-4944-8c25-0161d9c2d0ad.jpeg");
//        commonImgDto.setPayAgreement("/file/830b6ace-6864-42b4-9f39-166e9158855a.png");
//        commonImgDto.setAboutLogo("/file/e4cc3184-95e0-4944-8c25-0161d9c2d0ad.jpeg");

        /* 启明小学 */
        commonImgDto.setWelcomeLogo("/file/c9bf7892-393a-49f0-a746-04037605ba19.jpeg");
        commonImgDto.setPayAgreement("/file/830b6ace-6864-42b4-9f39-166e9158855a.png");
        commonImgDto.setAboutLogo("/file/c9bf7892-393a-49f0-a746-04037605ba19.jpeg");

        return new ResponseEntity(new Result().ok(commonImgDto), HttpStatus.OK);
    }

}
