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

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.listvo.order.PunishOrderVO;
import com.gree.mall.manager.bean.listvo.param.ExamineZfireParamBean;
import com.gree.mall.manager.bean.order.OrderShareVO;
import com.gree.mall.manager.bean.order.PunishOrderBean;
import com.gree.mall.manager.enums.ExamineStatusEnum;
import com.gree.mall.manager.exception.RemoteServiceException;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.order.PunishOrderLogic;
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;

/**
 * 处罚单
 * @author ：lijh
 * @description：TODO
 * @date ：2024/2/29 12:51
 */
@RequiredArgsConstructor
@Slf4j
@RestController
@Api(value = "处罚单管理", tags = {"处罚单管理"})
@RequestMapping(value = "/order/punish", produces = "application/json; charset=utf-8")
public class PunishOrderController {

    private final PunishOrderLogic punishOrderLogic;

    @ZfireList
    @PostMapping("/list")
    @ApiOperation("列表")
    public ResponseHelper<PunishOrderVO> list(
            @RequestBody ExamineZfireParamBean zfireParamBean
    ){
        IPage<PunishOrderVO> list = punishOrderLogic.list(zfireParamBean);
        return ResponseHelper.success(list, new TypeReference<PunishOrderVO>(){});
    }

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

    @PostMapping("/save")
    @ApiOperation("保存(传id则编辑)")
    public ResponseHelper save(
            @RequestBody PunishOrderBean punishOrderBean
    ) throws RemoteServiceException {
        punishOrderLogic.save(punishOrderBean);
        return ResponseHelper.success();
    }

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

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

    @PostMapping("/examine")
    @ApiOperation("审核")
    public ResponseHelper examine(
            @RequestParam String id,
            @ApiParam("OK=通过 FAIL=不通过") @RequestParam ExamineStatusEnum status,
            @ApiParam(value = "审核备注",required = false) @RequestParam(required = false) String examineRemark
    ){
        punishOrderLogic.examine(id,status,examineRemark);
        return ResponseHelper.success();
    }


}
