package com.fs.app.controller;


import com.fs.app.annotation.Login;
import com.fs.app.utils.JwtUtils;
import com.fs.common.core.domain.R;
import com.fs.company.domain.Company;
import com.fs.company.domain.CompanyUser;
import com.fs.company.service.ICompanyService;
import com.fs.company.service.ICompanyUserService;
import com.fs.crm.domain.CrmCustomer;
import com.fs.crm.domain.CrmCustomerVisit;
import com.fs.crm.param.*;
import com.fs.crm.service.ICrmCustomerLogsService;
import com.fs.crm.service.ICrmCustomerService;
import com.fs.crm.service.ICrmCustomerUserService;
import com.fs.crm.service.ICrmCustomerVisitService;
import com.fs.crm.vo.*;
import com.fs.store.service.IFsStoreOrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.fs.common.constant.Constants.PAGE_SIZE;


@Api("首页接口")
@RestController
@RequestMapping(value="/app/index")
public class IndexController extends  AppBaseController {
	@Autowired
    JwtUtils jwtUtils;
	@Autowired
	ICrmCustomerService crmCustomerService;
	@Autowired
	IFsStoreOrderService storeOrderService;
	@Autowired
	ICompanyUserService companyUserService;
	@Autowired
	ICrmCustomerUserService crmCustomerUserService;
	@Autowired
	private ICompanyService companyService;
	@Login
	@ApiOperation("获取首页数据")
	@GetMapping("/getIndexData")
	public R getIndexData(CrmFullCustomerListQueryParam param){
		Company company=companyService.selectCompanyById(getCompanyId());
		//获取统计数据
		Integer newCustomerCounts=crmCustomerService.selectCrmCustomerCountByType(company.getCompanyId(),1);
		Integer fullCustomerCounts=crmCustomerService.selectCrmCustomerCountByType(company.getCompanyId(),2);
		Integer myCustomerCounts=crmCustomerUserService.selectCrmMyCustomerUserCount(company.getCompanyId(),Long.parseLong(getUserId()));

		Integer dayOrderCounts=storeOrderService.selectFsStoreOrderCountByType(company.getCompanyId(),Long.parseLong(getUserId()),1);
		Integer doBuyOrderCounts=storeOrderService.selectFsStoreOrderCountByType(company.getCompanyId(),Long.parseLong(getUserId()),2);
		Map<String,Object> data=new HashMap<>();
		data.put("company",company);
		data.put("newCustomerCounts",newCustomerCounts);
		data.put("fullCustomerCounts",fullCustomerCounts);
		data.put("myCustomerCounts",myCustomerCounts);
		data.put("dayOrderCounts",dayOrderCounts);
		data.put("doBuyOrderCounts",doBuyOrderCounts);

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


}
