package com.jsowell.web.controller.index;

import com.alibaba.fastjson2.JSONObject;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.pile.service.IOrderBasicInfoService;
import com.jsowell.pile.vo.web.IndexGeneralSituationVO;
import com.jsowell.pile.dto.IndexQueryDTO;
import com.jsowell.pile.service.IPileBasicInfoService;
import com.jsowell.pile.vo.web.IndexOrderInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 首页数据展示Controller
 *
 * @author JS-ZZA
 * @date 2023/2/3 10:11
 */
@RestController
@RequestMapping("/index")
public class indexController extends BaseController {
    @Autowired
    IPileBasicInfoService pileBasicInfoService;

    @Autowired
    IOrderBasicInfoService orderBasicInfoService;

    @PostMapping("/getGeneralSituation")
    public RestApiResponse<?> getGeneralSituation(@RequestBody IndexQueryDTO dto) {
        logger.info("首页基础数据查询 param:{}", JSONObject.toJSONString(dto));
        RestApiResponse<?> response;
        try {
            IndexGeneralSituationVO generalSituation = pileBasicInfoService.getGeneralSituation(dto);
            response = new RestApiResponse<>(generalSituation);
        }catch (Exception e) {
            logger.error("首页数据查询错误:{}", e.getMessage());
            response = new RestApiResponse<>("00200001", "首页基础数据查询错误");
        }
        logger.info("首页数据查询 result:{}", JSONObject.toJSONString(response));
        return response;
    }

    /**
     * 首页订单数据汇总信息
     *
     * @param dto
     * @return
     */
    @PostMapping("/getOrderInfo")
    public RestApiResponse<?> getOrderInfo(@RequestBody IndexQueryDTO dto) {
        logger.info("首页订单相关信息查询 param:{}", JSONObject.toJSONString(dto));
        RestApiResponse<?> response;
        try {
            List<IndexOrderInfoVO> indexOrderInfo = orderBasicInfoService.getIndexOrderInfo(dto);
            response = new RestApiResponse<>(indexOrderInfo);
        } catch (Exception e) {
            logger.error("首页订单相关信息查询错误！{}", e.getMessage());
            response = new RestApiResponse<>("00200002", "首页订单数据查询错误");
        }
        logger.info("首页订单相关信息查询 result:{}", JSONObject.toJSONString(response));
        return response;
    }


}
