package com.fs.app.controller;

import com.fs.common.core.domain.R;
import com.fs.qw.domain.QwUser;
import com.fs.qw.param.QwMaterialParam;
import com.fs.qw.param.QwMaterialParamBySidebar;
import com.fs.qw.service.IQwExternalContactService;
import com.fs.qw.service.IQwMaterialService;
import com.fs.qw.vo.QwMaterialVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("素材库库相关接口")
@RestController
@RequestMapping("/app/qw/material")
@Slf4j
public class QwMaterialBySidebar {



    @Autowired
    private IQwExternalContactService qwExternalContactService;

    @Autowired
    private IQwMaterialService qwMaterialService;

    /**
     * 查询素材库列表
     */
    @PostMapping("/MaterialList")
    public R list(@RequestBody QwMaterialParamBySidebar param)
    {

        QwUser qwUser = qwExternalContactService.getQwUserByRedis(param.getCorpId().trim(),param.getQwUserId().trim());

        if (qwUser == null || qwUser.getCompanyId() == null) {
            return R.error("员工未绑定 销售公司 或 未获取到员工信息，请重试！");
        }


        PageHelper.startPage(param.getPageNum(), param.getPageSize());

        QwMaterialParam materialParam=new QwMaterialParam();
        materialParam.setCompanyId(qwUser.getCompanyId());
        materialParam.setTitle(param.getKeyword());
        List<QwMaterialVO> list = qwMaterialService.selectQwMaterialList(materialParam);


        PageInfo<QwMaterialVO> result = new PageInfo<>(list);
        return R.ok().put("data", result);

    }

    @GetMapping("/updateMaterialTime/{materialId}")
    public R updateMaterialTime(@PathVariable Long materialId) throws Exception {

        return R.ok().put("data",qwMaterialService.selectQwMaterialByMaterialIdByTime(materialId));
    }

    @GetMapping("/getMaterialByTime/{materialId}")
    public R getMaterialByTime(@PathVariable Long materialId) throws Exception {

        return R.ok().put("data",qwMaterialService.selectQwMaterialByMaterialIdByTimeTwo(materialId));
    }

}
