package com.gic.haoban.manage.web.controller.chat;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gic.api.base.commons.BasePageInfo;
import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.DateUtil;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.haoban.base.api.common.pojo.dto.WebLoginDTO;
import com.gic.haoban.common.utils.AuthWebRequestUtil;
import com.gic.haoban.manage.api.dto.chat.GroupChatDataDTO;
import com.gic.haoban.manage.api.dto.qdto.chat.ChatDataSearchQDTO;
import com.gic.haoban.manage.api.service.chat.GroupChatDataApiService;
import com.gic.haoban.manage.web.vo.chat.GroupChatDataVO;

/**
 * 
* @ClassName: GroupChatDataController
* @Description: 群统计
* @author xugh
* @date 2022年11月26日 上午9:32:56
*
 */
@RestController
@RequestMapping("/chat/data")
public class GroupChatDataController {

    @Autowired
    private GroupChatDataApiService groupChatDataApiService;

    @RequestMapping("total")
    public RestResponse<Object> listTotalData(@RequestBody ChatDataSearchQDTO qdto) {
        WebLoginDTO loginUser = AuthWebRequestUtil.getLoginUser();
        String wxEnterpriseId = loginUser.getWxEnterpriseId();
        qdto.setWxEnterpriseId(wxEnterpriseId);
        qdto.setStartDate(DateUtil.getStartTimeOfDay(qdto.getStartDate()));
        ServiceResponse<GroupChatDataDTO> resp = this.groupChatDataApiService.listTotalData(qdto);
        GroupChatDataVO vo = EntityUtil.changeEntityByJSON(GroupChatDataVO.class, resp.getResult());
        return RestResponse.successResult(vo);
    }

    @RequestMapping("list-chat")
    public RestResponse<Object> listForChat(@RequestBody ChatDataSearchQDTO qdto) {
        WebLoginDTO loginUser = AuthWebRequestUtil.getLoginUser();
        String wxEnterpriseId = loginUser.getWxEnterpriseId();
        qdto.setWxEnterpriseId(wxEnterpriseId);
        qdto.setStartDate(DateUtil.getStartTimeOfDay(qdto.getStartDate()));
        ServiceResponse<List<GroupChatDataDTO>> resp = this.groupChatDataApiService.listForChat(qdto);
        List<GroupChatDataVO> list = EntityUtil.changeEntityListByJSON(GroupChatDataVO.class, resp.getResult());
        return RestResponse.successResult(list);
    }

    @RequestMapping("list-staff")
    public RestResponse<Object> listStaffData(@RequestBody ChatDataSearchQDTO qdto) {
        BasePageInfo basePageInfo = new BasePageInfo() ;
        basePageInfo.setPageNum(qdto.getPageNum());
        basePageInfo.setPageSize(qdto.getPageSize());
        WebLoginDTO loginUser = AuthWebRequestUtil.getLoginUser();
        String wxEnterpriseId = loginUser.getWxEnterpriseId();
        qdto.setWxEnterpriseId(wxEnterpriseId);
        qdto.setStartDate(DateUtil.getStartTimeOfDay(qdto.getStartDate()));
        ServiceResponse<Page<GroupChatDataDTO>> resp = this.groupChatDataApiService.listStaffData(qdto, basePageInfo);
        Page<GroupChatDataDTO> page = resp.getResult();
        List<GroupChatDataVO> list = EntityUtil.changeEntityListByJSON(GroupChatDataVO.class, page.getResult());
        Page<GroupChatDataVO> retPage = new Page<>();
        retPage.setTotalCount(page.getTotalCount());
        retPage.setCurrentPage(page.getCurrentPage());
        retPage.setPageSize(page.getPageSize());
        retPage.setResult(list);
        return RestResponse.successResult(retPage);
    }

}
