package cn.wisenergy.web.admin.controller.app;

import cn.wisenergy.common.utils.Result;
import cn.wisenergy.model.app.Page;
import cn.wisenergy.model.app.shopZx;
import cn.wisenergy.service.app.UploadService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.*;


/**
 * Created by m1991 on 2021/2/24 13:46
 */
@Api(tags = "资讯管理")
@RestController
@RequestMapping("/ZX")
@Slf4j
public class UploadController {

    @Autowired
    private UploadService uploadService;

    /**
     * @param request
     * @return
     * @throws Exception
     */
    /**
     * 视频文件上传
     * 资讯主键id* 视频/封面存放地址* 用户id(作者id)
     * 获赞数* 视频/图片名称* 审核字段* 资讯文字输入字段
     * 资讯创建时间* 图片储存地址* 资讯发表地址
     *
     * @param file
     * @param request
     * @param userId
     * @param zxField
     * @param zxAddress
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "资讯信息-文字/视频上传接口", notes = "返回路径给前台", httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "zxField", value = "资讯文字", dataType = "String"),
            @ApiImplicitParam(name = "file", value = "视频文件", dataType = "MultipartFile"),
            @ApiImplicitParam(name = "zxAddress", value = "资讯发布地址", dataType = "String"),
            @ApiImplicitParam(name = "userId", value = "用户手机号（发布人）", required = true, dataType = "String")})
    @RequestMapping(value = "/uploadVideo", method = RequestMethod.POST)
    public Map<String, Object> uploadVideo(MultipartFile file, HttpServletRequest request, String userId, String zxField, String zxAddress) throws Exception {
        return uploadService.uploadVideo(file, request, userId, zxField, zxAddress);
    }

    /**
     * 单图片文件上传
     *
     * @param request
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "资讯信息-文字/单图片上传接口", notes = "返回路径给前台", httpMethod = "POST", produces = "application/json; charset=UTF-8")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "zxField", value = "资讯文字", dataType = "String"),
            @ApiImplicitParam(name = "file", value = "单图片", dataType = "MultipartFile"),
            @ApiImplicitParam(name = "zxAddress", value = "资讯发布地址", dataType = "String"),
            @ApiImplicitParam(name = "userId", value = "用户手机号", required = true, dataType = "String")})
    @RequestMapping(value = "/uploadImage", method = RequestMethod.POST)
    public Map<String, Object> uploadImage(MultipartFile file, HttpServletRequest request, String userId, String zxField, String zxAddress) throws Exception {


        return uploadService.uploadImage(file, request, userId, zxField, zxAddress);
    }


    /**
     * 多文件上传
     *
     * @param files    @RequestParam("file")    /**
     * *  多文件上传接口
     * *  T0D0 value = "/fileUpload", produces = "application/json;charset=UTF-8
     * *
     * @return
     */
    private static final Logger logger = LoggerFactory.getLogger(UploadController.class);

    @ApiOperation(value = "资讯信息-文字/多图片上传接口", notes = "上传图片,返回路径给前台", httpMethod = "POST", produces = "application/json; charset=UTF-8")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "zxField", value = "资讯文字", dataType = "String"),
            @ApiImplicitParam(name = "file[]", value = "多图片", dataType = "MultipartFile"),
            @ApiImplicitParam(name = "zxAddress", value = "发表地址", dataType = "String"),
            @ApiImplicitParam(name = "userId", value = "用户手机号", required = true, dataType = "String")})
    @RequestMapping("/multipleImageUpload")
    public List multipleImageUpload(MultipartFile[] files, String userId, String zxField, String zxAddress) {
        return uploadService.imageUpload(files, userId, zxField, zxAddress);

    }

    /**
     * 资讯分页展示接口
     * @param pageOffset
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "资讯信息-文字/多图片上传接口", notes = "上传图片,返回路径给前台", httpMethod = "POST", produces = "application/json; charset=UTF-8")
    @ApiImplicitParams({

            @ApiImplicitParam(name = "beginPos", value = "从几开始", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "展示数量（条数）", required = true, dataType = "Integer")})
    @RequestMapping(value = "/shop", method = {RequestMethod.POST, RequestMethod.GET})
    public Result find(Integer beginPos, Integer pageSize) {
        Page<shopZx> shopZxPage = (Page<shopZx>) uploadService.getList(beginPos, pageSize);

        return new Result(String.valueOf(0), "success", shopZxPage);
    }


}