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

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.third.ThirdPartyVO;
import com.gree.mall.manager.bean.websit.SettlementOrderDetail;
import com.gree.mall.manager.bean.websit.SettlementOrderLogicVO;
import com.gree.mall.manager.bean.websit.WorkerSettlementLineVO;
import com.gree.mall.manager.bean.websit.WorkerSettlementVO;
import com.gree.mall.manager.bean.workorder.IncreAddOrUp;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.third.ThirdPartyLogic;
import com.gree.mall.manager.logic.websit.SettlementOrderLogic;
import com.gree.mall.manager.plus.entity.ThirdParty;
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.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.util.List;

@Slf4j
@RestController
@Api(value = "第三方网址", tags = {"第三方网址"})
@RequestMapping(value = "/thirdPart", produces = "application/json; charset=utf-8")
public class ThirdPartyController {

    @Autowired
    private ThirdPartyLogic thirdPartyLogic;

    @ZfireList
    @PostMapping("/list/page")
    @ApiOperation(value = "第三方网址列表")
    public ResponseHelper<IPage<ThirdPartyVO>> pageSettlementV2(
            @RequestBody ZfireParamBean zfireParamBean
    ) {
        IPage<ThirdPartyVO> page = thirdPartyLogic.page(zfireParamBean);
        return ResponseHelper.success(page, new TypeReference<ThirdPartyVO>() {});
    }

    @PostMapping("/pageExport")
    @ApiOperation(value = "第三方网址导出")
    public void pageSettlementExport(@RequestBody ZfireParamBean zfireParamBean, HttpServletRequest request, HttpServletResponse response) throws Exception {
        //1.组装查询条件
        ZfireParamBean zfireParam = FieldUtils.supplyParam(zfireParamBean);
        //2.查询要导出的内容
        IPage<ThirdPartyVO> page = thirdPartyLogic.page(zfireParamBean);
        //3.导出
        FieldUtils.exportData(page.getRecords(), zfireParam.getExportFields(), request, response);
    }


    @PostMapping("/detail")
    @ApiOperation("第三方网址详情")
    public ResponseHelper<ThirdParty> detail(
            @ApiParam(value = "第三方网址id" , required = true) @RequestParam(required = true) String id,

            HttpServletRequest request
    ) throws ParseException {
        ThirdParty  thirdParty = thirdPartyLogic.detail(id);
        return ResponseHelper.success(thirdParty);
    }



    @PostMapping("/add")
    @ApiOperation("添加第三方网址详情")
    public ResponseHelper add(
            @RequestBody ThirdParty thirdParty,
            HttpServletRequest request
    ) throws ParseException {
        thirdPartyLogic.add(thirdParty);
        return ResponseHelper.success();
    }

    @PostMapping("/update")
    @ApiOperation("修改第三方网址详情")
    public ResponseHelper update(
            @RequestBody ThirdParty thirdParty,
            HttpServletRequest request
    ) throws ParseException {
        thirdPartyLogic.update(thirdParty);
        return ResponseHelper.success();
    }


    @PostMapping("/del")
    @ApiOperation("删除第三方网址详情")
    public ResponseHelper del(
            @ApiParam(value = "第三方网址id" , required = true) @RequestParam(required = true) String id,
            HttpServletRequest request
    ) throws ParseException {
        thirdPartyLogic.del(id);
        return ResponseHelper.success();
    }

}
