package org.jeecg.modules.ctop.controller;

import cn.com.ctop.common.module.utils.Check;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.ctop.service.IMaterialUploadTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 素材归属标
 *
 * @author jeecg-boot
 * @version V1.0
 * @date 2019-11-23
 */
@Slf4j
@Api(tags = "素材归属标")
@RestController
@RequestMapping("/ctop/materialUpload")
public class MaterialUploadController {
    @Autowired
    private IMaterialUploadTaskService materialUploadTaskService;

    @ResponseBody
    @PostMapping(value = "/uploadAccount")
    public JSONObject uploadAccount(@RequestBody JSONObject json) {
        JSONObject returnJson = materialUploadTaskService.submitTask(json);
        return returnJson;
    }


    @GetMapping(value = "/uploadDetail")
    public Result<PageInfo<List<JSONObject>>> uploadDetail(String signature, Integer pageNo, Integer pageSize) {
        Result<PageInfo<List<JSONObject>>> result = new Result<>();
        try {
            if (Check.isNull(signature)) {
                throw new Exception("请输入md5");
            }
            if (Check.isNull(pageNo)) {
                throw new Exception("请输入页数");
            }
            if (Check.isNull(pageSize)) {
                throw new Exception("请输入每页条数");
            }
            PageInfo<List<JSONObject>> listPageInfo = materialUploadTaskService.uploadDetail(signature, pageNo, pageSize);
            result.setSuccess(true);
            result.setResult(listPageInfo);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage(e.getMessage());

        }
        return result;

    }

}
