package com.fs.app.controller;

import com.alibaba.fastjson.JSON;
import com.fs.app.annotation.Login;
import com.fs.common.core.domain.R;
import com.fs.qw.domain.QwWorkTask;
import com.fs.qw.service.IQwUserService;
import com.fs.qw.service.IQwWorkTaskService;
import com.fs.app.param.QwWorkTaskQueryParam;
import com.fs.qw.vo.QwOptionsVO;
import com.fs.qw.vo.UserVOs;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.*;

@Slf4j
@Api(tags = "企微任务看板接口")
@RestController
@RequestMapping("/app/qwWorkTask")
@AllArgsConstructor
public class QwWorkTaskController extends AppBaseController {

    private final IQwWorkTaskService qwWorkTaskService;
    private final IQwUserService qwUserService;

    @Login
    @ApiOperation("企微任务看板列表")
    @GetMapping("/list")
    public R list (@Valid QwWorkTaskQueryParam param) {
        log.debug("企微任务看板列表:{}", JSON.toJSONString(param));

        Map<String, Object> params = new HashMap<>();
        params.put("qwUserId", param.getQwUserId());
        params.put("companyId", getCompanyId());
        params.put("companyUserId", getUserId());
        params.put("date", param.getDate());

        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        List<QwWorkTask> list = qwWorkTaskService.selectQwWorkTaskListByMap(params);

        PageInfo<QwWorkTask> pageInfo = new PageInfo<>(list);
        return R.ok().put("data", pageInfo);
    }

    @Login
    @ApiOperation("销售下的企微用户")
    @GetMapping("/getMyQwUserList")
    public R userList(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                      @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        Long userId = Long.parseLong(getUserId());
        PageHelper.startPage(pageNum, pageSize);
        List<QwOptionsVO> list = qwUserService.selectQwUserListOptionsVOByCompanyUserId(userId);
        return R.ok().put("data", new PageInfo<>(list));
    }

    @Login
    @ApiOperation("催课看板会员列表")
    @GetMapping("/getUserList")
    public R getUserList(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                      @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        Long userId = Long.parseLong(getUserId());
        PageHelper.startPage(pageNum, pageSize);
        List<UserVOs> list = qwUserService.getUserList(userId);
        return R.ok().put("data", new PageInfo<>(list));
    }

}
