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.ExcelData;
import com.gree.mall.manager.bean.activity.PromotionActivityBatchBean;
import com.gree.mall.manager.bean.activity.PromotionActivityBean;
import com.gree.mall.manager.bean.activity.PromotionActivityVO;
import com.gree.mall.manager.bean.apply.WorkerInvolvePrincipalDetail;
import com.gree.mall.manager.bean.apply.WorkerInvolvePrincipalVO;
import com.gree.mall.manager.bean.es.ESGoodsVO;
import com.gree.mall.manager.exception.RemoteServiceException;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.activity.PromotionActivityLogic;
import com.gree.mall.manager.logic.apply.WorkerInvolveLogic;
import com.gree.mall.manager.utils.excel.ExcelUtils;
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.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;

@Slf4j
@RestController
@Api(value = "难度费用审批人设置", tags ={"难度费用审批人设置"} )
@RequestMapping(value = "/principal", produces = "application/json; charset=utf-8")
public class PrincipalController {

    @Resource
    WorkerInvolveLogic workerInvolveLogic;

    @ZfireList
    @PostMapping("/list")
    @ApiOperation(value = "难度费用审批人设置-列表")
    public ResponseHelper<IPage<WorkerInvolvePrincipalVO>> list(
            @RequestBody ZfireParamBean zfireParamBean
    ) {
        IPage<WorkerInvolvePrincipalVO> page = workerInvolveLogic.list(zfireParamBean);
        return ResponseHelper.success(page, new TypeReference<WorkerInvolvePrincipalVO>() {});
    }

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


    @PostMapping("/detail")
    @ApiOperation(value = "难度费用审批人设置-详情")
    public ResponseHelper<WorkerInvolvePrincipalDetail> detail(
            @ApiParam(value = "id", required = true) @RequestParam String id
    ) throws RemoteServiceException {
        WorkerInvolvePrincipalDetail bean = workerInvolveLogic.detail(id);
        return ResponseHelper.success(bean);
    }

    @PostMapping("/add")
    @ApiOperation(value = "难度费用审批人设置-新增")
    public ResponseHelper add(
            HttpServletRequest request,
            @RequestBody WorkerInvolvePrincipalDetail bean
    ) throws Exception {
        workerInvolveLogic.add(bean);
        return ResponseHelper.success();
    }

    @PostMapping("/update")
    @ApiOperation(value = "难度费用审批人设置-修改")
    public ResponseHelper update(
            @RequestBody WorkerInvolvePrincipalDetail bean
    ) throws Exception {
        workerInvolveLogic.update(bean);
        return ResponseHelper.success();
    }
}
