package com.jeeplus.test.wdt.merchantCompany.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.jeeplus.aop.logging.annotation.ApiLog;
import com.jeeplus.core.query.QueryWrapperGenerator;
import com.jeeplus.test.wdt.merchantCompany.service.SettledPlatformService;
import com.jeeplus.test.wdt.merchantCompany.service.dto.SettledPlatformDTO;
import com.jeeplus.test.wdt.merchantCompany.service.mapstuct.SettledPlatformWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 入驻平台controller
 * @author: 徐滕
 * @version: 2024-01-04 15:12
 */
@Api("入驻平台管理")
@RestController
@RequestMapping(value = "/wdt/settledPlatform")
public class SettledPlatformController {
    @Autowired
    private SettledPlatformService settledPlatformService;

    @Autowired
    private SettledPlatformWrapper settledPlatformWrapper;

    /**
     * 入驻平台列表数据
     */
    @ApiLog("查询入驻平台列表数据")
    @ApiOperation(value = "查询入驻平台列表数据")
    @PreAuthorize("hasAuthority('wdt:settledPlatform:list')")
    @GetMapping("list")
    public ResponseEntity<IPage<SettledPlatformDTO>> list(SettledPlatformDTO settledPlatformDTO, Page<SettledPlatformDTO> page) throws Exception {
        IPage<SettledPlatformDTO> result = settledPlatformService.findPage (page, settledPlatformDTO);
        return ResponseEntity.ok (result);
    }

    /**
     * 根据Id获取商家基本信息
     */
    @ApiLog("根据Id获取入驻平台基本信息")
    @ApiOperation(value = "根据Id获取入驻平台基本信息")
    @PreAuthorize("hasAnyAuthority('wdt:settledPlatform:view','wdt:settledPlatform:add','wdt:settledPlatform:edit')")
    @GetMapping("queryById")
    public ResponseEntity<SettledPlatformDTO> queryById(String id) {
        return ResponseEntity.ok ( settledPlatformService.findById ( id ) );
    }



    /**
     * 保存请假表单
     */
    @ApiLog("保存入驻平台基本信息")
    @ApiOperation(value = "保存入驻平台基本信息")
    @PreAuthorize("hasAnyAuthority('wdt:settledPlatform:add','wdt:settledPlatform:edit')")
    @PostMapping("save")
    public ResponseEntity<String> save(@Valid @RequestBody SettledPlatformDTO settledPlatformDTO) {
        //新增或编辑表单保存
        settledPlatformService.saveOrUpdate (settledPlatformWrapper.toEntity (settledPlatformDTO));
        return ResponseEntity.ok ( "保存入驻平台基本信息成功" );
    }


    /**
     * 删除请假表单
     */
    @ApiLog("删除入驻平台基本信息")
    @ApiOperation(value = "删除入驻平台基本信息")
    @PreAuthorize("hasAuthority('wdt:settledPlatform:del')")
    @DeleteMapping("delete")
    public ResponseEntity <String> delete(String ids) {
        String idArray[] = ids.split(",");
        settledPlatformService.removeByIds ( Lists.newArrayList ( idArray ) );
        return ResponseEntity.ok( "删除入驻平台基本信息成功" );
    }
}
