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

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.test.wdt.merchantCompany.service.CompanyTypeService;
import com.jeeplus.test.wdt.merchantCompany.service.dto.CompanyTypeDTO;
import com.jeeplus.test.wdt.merchantCompany.service.mapstuct.CompanyTypeWrapper;
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/merchantCompanyType")
public class MerchantCompanyTypeController {
    @Autowired
    private CompanyTypeService companyTypeService;

    @Autowired
    private CompanyTypeWrapper companyTypeWrapper;

    /**
     * 入驻产品列表数据
     */
    @ApiLog("查询入驻公司类型列表数据")
    @ApiOperation(value = "查询入驻公司类型列表数据")
    @PreAuthorize("hasAuthority('wdt:merchantCompanyType:list')")
    @GetMapping("list")
    public ResponseEntity<IPage<CompanyTypeDTO>> list(CompanyTypeDTO companyTypeDTO, Page<CompanyTypeDTO> page) throws Exception {
        IPage<CompanyTypeDTO> result = companyTypeService.findPage (page, companyTypeDTO);
        return ResponseEntity.ok (result);
    }

    /**
     * 根据Id获取商家基本信息
     */
    @ApiLog("根据Id获取入驻公司类型基本信息")
    @ApiOperation(value = "根据Id获取入驻公司类型基本信息")
    @PreAuthorize("hasAnyAuthority('wdt:merchantCompanyType:view','wdt:merchantCompanyType:add','wdt:merchantCompanyType:edit')")
    @GetMapping("queryById")
    public ResponseEntity<CompanyTypeDTO> queryById(String id) {
        return ResponseEntity.ok ( companyTypeService.findById ( id ) );
    }



    /**
     * 保存请假表单
     */
    @ApiLog("保存入驻公司类型基本信息")
    @ApiOperation(value = "保存入驻公司类型基本信息")
    @PreAuthorize("hasAnyAuthority('wdt:merchantCompanyType:add','wdt:merchantCompanyType:edit')")
    @PostMapping("save")
    public ResponseEntity<String> save(@Valid @RequestBody CompanyTypeDTO companyTypeDTO) {
        //新增或编辑表单保存
        companyTypeService.saveOrUpdate (companyTypeWrapper.toEntity (companyTypeDTO));
        return ResponseEntity.ok ( "保存入驻产品基本信息成功" );
    }


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


}
