package com.jsowell.api.uniapp.business;

import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.ImmutableMap;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.pile.dto.StationStatisticsInfoDTO;
import com.jsowell.pile.service.PileStationInfoService;
import com.jsowell.pile.vo.uniapp.business.StationStatisticsInfosVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 运营端小程序站点信息Controller
 *
 * @author Lemon
 * @Date 2024/7/16 13:44:06
 */
@RestController
@RequestMapping("/business/pile/station")
public class BusinessStationInfoController extends BaseController {

    @Autowired
    private PileStationInfoService pileStationInfoService;

    /**
     * 获取站点统计信息
     * @param dto
     * @return
     */
    @PostMapping("/getStationStatisticsInfos")
    public RestApiResponse<?> getStationStatisticsInfos(@RequestBody StationStatisticsInfoDTO dto) {
        RestApiResponse<?> response = null;
        try {
            List<StationStatisticsInfosVO> stationStatisticsInfos = pileStationInfoService.getStationStatisticsInfos(dto);
            response = new RestApiResponse<>(ImmutableMap.of("stationStatisticsInfos", stationStatisticsInfos));
        } catch (Exception e) {
            logger.error("获取站点统计信息 error", e);
            response = new RestApiResponse<>(e);
        }
        logger.info("获取站点统计信息 params:{}, result:{}", JSONObject.toJSONString(dto), response);
        return response;
    }
}
