package com.fs.app.controller.qw;

import com.fs.app.controller.AppBaseController;
import com.fs.common.core.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.qw.param.QwExternalContactParam;
import com.fs.qw.service.IQwExternalContactService;
import com.fs.qw.vo.QwExternalContactVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping(value="/app/externalContact")
public class QwExternalContactController extends AppBaseController {

    @Autowired
    private IQwExternalContactService qwExternalContactService;

    @ApiOperation("我的企微客户")
    @GetMapping("/myList")
    public R myList(QwExternalContactParam qwExternalContact)
    {
        if(qwExternalContact.getQwUserId()==null && qwExternalContact.getCompanyId() == null){
            return null;
        }
        //PageHelper.startPage(qwExternalContact.getPageNum(), qwExternalContact.getPageSize());
        startPage();
        List<QwExternalContactVO> list = qwExternalContactService.selectQwExternalContactListVO(qwExternalContact);
        if (!CollectionUtils.isEmpty(list)) {
            list = list.stream().filter(s -> s.getFsUserId() != null).collect(Collectors.toList());
        }
        PageInfo<QwExternalContactVO> pageInfo = new PageInfo<>(list);
        return R.ok().put("data", pageInfo);
    }
}
