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



import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gree.mall.manager.annotation.ZfireList;
import com.gree.mall.manager.bean.apply.WorkerInvolveApplyDetail;
import com.gree.mall.manager.bean.apply.WorkerInvolveApplyVO;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.apply.WorkerInvolveLogic;
import com.gree.mall.manager.plus.entity.LeLetterItem;
import com.gree.mall.manager.plus.entity.WorkerInvolveApplyItem;
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.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;


@Slf4j
@RestController
@Api(value = "难度费用申请", tags = {"难度费用申请"})
@RequestMapping(value = "/workerApply", produces = "application/json; charset=utf-8")
public class WorkerInvolveController {

    @Resource
    WorkerInvolveLogic workerInvolveLogic;



    @ZfireList
    @PostMapping("/list")
    @ApiOperation(value = "难度费用申请-列表")
    public ResponseHelper<IPage<WorkerInvolveApplyVO>> listApply(
            @RequestBody ZfireParamBean zfireParamBean
    ) {
        IPage<WorkerInvolveApplyVO> page = workerInvolveLogic.listApply(zfireParamBean);
        return ResponseHelper.success(page, new TypeReference<WorkerInvolveApplyVO>() {});
    }

    @PostMapping("/list/export")
    @ApiOperation("难度费用申请-导出")
    public void listExport(
            @RequestBody ZfireParamBean zfireParamBean,
            HttpServletRequest request,
            HttpServletResponse response
    ) throws Exception {
        //2.查询要导出的内容
        IPage<WorkerInvolveApplyVO> baseVOIPage = workerInvolveLogic.listApply(zfireParamBean);
        //3.导出
        FieldUtils.exportData(baseVOIPage.getRecords(), zfireParamBean.getExportFields(), request, response);
    }


    @PostMapping("/detail")
    @ApiOperation(value = "难度费详情")
    public ResponseHelper<WorkerInvolveApplyDetail> detailApply(
            @ApiParam("id") @RequestParam String orderBaseId,
            HttpServletRequest request
    ) throws Exception {

        WorkerInvolveApplyDetail workerInvolveApplyDetail = workerInvolveLogic.detailApply(orderBaseId);
        return ResponseHelper.success(workerInvolveApplyDetail);
    }

    @PostMapping("/websitAppeal")
    @ApiOperation("网点审批")
    public ResponseHelper websitAppeal(
            @RequestBody WorkerInvolveApplyItem workerInvolveApplyItem,
            HttpServletRequest request
    ) throws ParseException {
        workerInvolveLogic.websitAppeal(workerInvolveApplyItem);
        return ResponseHelper.success();
    }


    @PostMapping("/appeal")
    @ApiOperation("中心审批")
    public ResponseHelper appeal(
            @RequestBody WorkerInvolveApplyItem workerInvolveApplyItem,
            HttpServletRequest request
    ) throws ParseException {
        workerInvolveLogic.appeal(workerInvolveApplyItem);
        return ResponseHelper.success();
    }


}
