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.workorder.OrderSmallTypeVO;
import com.gree.mall.manager.bean.websit.WithdrawalOrderVO;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.workorder.OrderSmallTypeLogic;
import com.gree.mall.manager.plus.entity.OrderSmallType;
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 lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RequiredArgsConstructor
@Slf4j
@RestController
@Api(value = "工单类型API", tags = {"工单类型API"})
@RequestMapping(value = "/order/smalltype", produces = "application/json; charset=utf-8")
public class OrderSmallTypeController {

    private final OrderSmallTypeLogic orderSmallTypeLogic;

    @ZfireList
    @PostMapping("/list")
    @ApiOperation(value = "列表")
    public ResponseHelper<Page<OrderSmallTypeVO>> list(
            @RequestBody ZfireParamBean zfireParamBean
    ) {
        IPage<OrderSmallTypeVO> orderSmallTypeVO = orderSmallTypeLogic.orderSmallTypeList(zfireParamBean);
        return ResponseHelper.success(orderSmallTypeVO, new TypeReference<OrderSmallTypeVO>() {});
    }

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

    @PostMapping("/save")
    @ApiOperation(value = "保存(传id则修改)")
    public ResponseHelper save(
            @RequestBody OrderSmallType orderSmallType
    ) {
        orderSmallTypeLogic.save(orderSmallType);
        return ResponseHelper.success();
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    public ResponseHelper delete(
            @RequestParam String id
    ) {
        orderSmallTypeLogic.delete(id);
        return ResponseHelper.success();
    }


    @PostMapping("/detail")
    @ApiOperation(value = "详情")
    public ResponseHelper<OrderSmallType> detail(
            @RequestParam String id
    ) {
        OrderSmallType detail = orderSmallTypeLogic.detail(id);
        return ResponseHelper.success(detail);
    }




}
