package com.huiju.estateagents.statistic.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huiju.estateagents.base.ResponseBean;
import com.huiju.estateagents.entity.TdBizEvent;
import com.huiju.estateagents.entity.TdBizEventType;
import com.huiju.estateagents.mapper.TdBizEventTypeMapper;
import com.huiju.estateagents.po.PersonPO;
import com.huiju.estateagents.statistic.entity.TsUserBehaviorStatistic;
import com.huiju.estateagents.statistic.mapper.TsUserBehaviorStatisticMapper;
import com.huiju.estateagents.statistic.service.ITsUserBehaviorStatisticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户行为统计表  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2020-01-13
 */
@Service
public class TsUserBehaviorStatisticServiceImpl extends ServiceImpl<TsUserBehaviorStatisticMapper, TsUserBehaviorStatistic> implements ITsUserBehaviorStatisticService {

    @Autowired
    private TsUserBehaviorStatisticMapper tsUserBehaviorStatisticMapper;

    @Autowired
    private TdBizEventTypeMapper tdBizEventTypeMapper;

    @Override
    public void userBehaviorStatustic() {
        //查询当天信息
        List<TsUserBehaviorStatistic> list = tsUserBehaviorStatisticMapper.seleUserBehaviorList();
        //删除当天信息
        tsUserBehaviorStatisticMapper.deleteByDate();
        //批量插入信息
        this.saveBatch(list);
    }

    /**
     * 按日期获取统计列表
     *
     * @param orgId
     * @param startDate
     * @param endDate
     * @param buildingId
     * @return
     */
    @Override
    public ResponseBean selectUserBehavior(Integer orgId, LocalDate startDate, LocalDate endDate, String buildingId) {
        ResponseBean responseBean = new ResponseBean();
        List<PersonPO> tsUserBehaviorStatistics = tsUserBehaviorStatisticMapper.seleBehaviorListByDate(orgId, startDate, endDate, buildingId);
        Map<String, Object> map = new HashMap<>();
        map.put("selectUserBehavior", tsUserBehaviorStatistics);
        responseBean.addSuccess(map);
        return responseBean;
    }
}
