package com.mortals.xhx.module.realtime.web;
import cn.hutool.core.date.DateUtil;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.base.system.param.service.ParamService;
import com.mortals.xhx.common.code.DaySelectEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.mortals.framework.model.Context;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.mortals.framework.web.BaseCRUDJsonBodyMappingController;
import com.mortals.xhx.module.realtime.model.RealtimeDataflowStatEntity;
import com.mortals.xhx.module.realtime.service.RealtimeDataflowStatService;
import org.apache.commons.lang3.ArrayUtils;
import com.mortals.framework.util.StringUtils;

import java.util.*;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import static com.mortals.framework.ap.SysConstains.*;
/**
*
* 人员流量统计
*
* @author zxfei
* @date 2023-04-19
*/
@RestController
@RequestMapping("realtime/dataflow/stat")
public class RealtimeDataflowStatController extends BaseCRUDJsonBodyMappingController<RealtimeDataflowStatService,RealtimeDataflowStatEntity,Long> {

    @Autowired
    private ParamService paramService;

    public RealtimeDataflowStatController(){
        super.setModuleDesc( "人员流量统计");
    }

    @Override
    protected void init(Map<String, Object> model, Context context) {
        super.init(model, context);
    }
    @Override
    protected void doListBefore(RealtimeDataflowStatEntity query, Map<String, Object> model, Context context) throws AppException {
        super.doListBefore(query, model, context);

        if (!ObjectUtils.isEmpty(query.getSelected())) {
            //转换日期
            switch (DaySelectEnum.getByValue(query.getSelected())) {
                case 今天:
                    query.setCreateTimeStart(DateUtil.today());
                    break;
                case 近七天:
                    query.setCreateTimeStart(DateUtil.offsetDay(new Date(),-7).toDateStr());
                    break;
                case 近三十天:
                    query.setCreateTimeStart(DateUtil.offsetDay(new Date(),-30).toDateStr());
                    break;
                case 近三月:
                    query.setCreateTimeStart(DateUtil.offsetMonth(new Date(),-3).toDateStr());
                    break;
                case 今年:
                    query.setCreateTimeStart(DateUtil.beginOfYear(new Date()).toDateStr());
                    break;
                default:
                    break;
            }
        }

    }

}