package com.gree.mall.manager.controller.workerorder;

import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gree.mall.manager.annotation.ZfireList;
import com.gree.mall.manager.bean.listvo.param.WorkOrderZfireParam;
import com.gree.mall.manager.bean.listvo.workorder.OrderBaseAppraiseVO;
import com.gree.mall.manager.bean.listvo.workorder.OrderBaseVO;
import com.gree.mall.manager.bean.workorder.OrderAddBeanDTO;
import com.gree.mall.manager.enums.workorder.OrderFlagEnum;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.workorder.OrderBaseLogic;
import com.gree.mall.manager.logic.workorder.OrderLogLogic;
import com.gree.mall.manager.plus.entity.PgOrderOperatorLog;
import com.gree.mall.manager.plus.entity.PgOrderProduct;
import com.gree.mall.manager.plus.entity.PgOrderWorker;
import com.gree.mall.manager.zfire.bean.ZfireParamBean;
import com.gree.mall.manager.zfire.util.FieldUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

@RequiredArgsConstructor
@Slf4j
@RestController
@Api(value = "工单评价API", tags = {"工单评价API"})
@RequestMapping(value = "/order/base/appraise", produces = "application/json; charset=utf-8")
public class OrderAppraiseController {

    private final OrderBaseLogic orderBaseLogic;

    @ZfireList
    @PostMapping("/list")
    @ApiOperation(value = "列表")
    public ResponseHelper<Page<OrderBaseAppraiseVO>> list(
            @RequestBody ZfireParamBean zfireParamBean
    ) {
        IPage<OrderBaseAppraiseVO> orderBaseVOIPage = orderBaseLogic.orderBaseAppraiseList(zfireParamBean);
        return ResponseHelper.success(orderBaseVOIPage, new TypeReference<OrderBaseAppraiseVO>() {});
    }

    @PostMapping("/list/export")
    @ApiOperation(value = "导出")
    public void listExport(@RequestBody WorkOrderZfireParam zfireParamBean, HttpServletRequest request, HttpServletResponse response) throws Exception {
        //1.组装查询条件
        ZfireParamBean zfireParam = FieldUtils.supplyParam(zfireParamBean);
        //2.查询要导出的内容
        IPage<OrderBaseAppraiseVO> page = orderBaseLogic.orderBaseAppraiseList(zfireParamBean);
        //3.导出
        FieldUtils.exportData(page.getRecords(), zfireParam.getExportFields(), request, response);
    }

}
