package com.zhongzheng.controller.system;

import java.util.List;
import java.util.Arrays;

import com.zhongzheng.modules.system.bo.SysTenantAddBo;
import com.zhongzheng.modules.system.bo.SysTenantEditBo;
import com.zhongzheng.modules.system.bo.SysTenantQueryBo;
import com.zhongzheng.modules.system.service.ISysTenantService;
import com.zhongzheng.modules.system.vo.SysTenantVo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhongzheng.common.annotation.Log;
import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.enums.BusinessType;
import com.zhongzheng.common.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 系统商户Controller
 *
 * @author hjl
 * @date 2021-08-03
 */
@Api(value = "系统商户控制器", tags = {"系统商户管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/tenant")
public class SysTenantController extends BaseController {

    private final ISysTenantService iSysTenantService;

    /**
     * 查询系统商户列表
     */
    @ApiOperation("查询系统商户列表")
    @PreAuthorize("@ss.hasPermi('system:tenant:list')")
    @GetMapping("/list")
    public TableDataInfo<SysTenantVo> list(SysTenantQueryBo bo) {
        startPage();
        List<SysTenantVo> list = iSysTenantService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出系统商户列表
     */
   /* @ApiOperation("导出系统商户列表")
    @PreAuthorize("@ss.hasPermi('system:tenant:export')")
    @Log(title = "系统商户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<SysTenantVo> export(SysTenantQueryBo bo) {
        List<SysTenantVo> list = iSysTenantService.queryList(bo);
        ExcelUtil<SysTenantVo> util = new ExcelUtil<SysTenantVo>(SysTenantVo.class);
        return util.exportExcel(list, "系统商户");
    }*/

    /**
     * 获取系统商户详细信息
     */
    @ApiOperation("获取系统商户详细信息")
    @PreAuthorize("@ss.hasPermi('system:tenant:query')")
    @GetMapping("/{tenantId}")
    public AjaxResult<SysTenantVo> getInfo(@PathVariable("tenantId" ) Long tenantId) {
        return AjaxResult.success(iSysTenantService.queryById(tenantId));
    }

    /**
     * 新增系统商户
     */
    @ApiOperation("新增系统商户")
    @PreAuthorize("@ss.hasPermi('system:tenant:add')")
    @Log(title = "系统商户", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody SysTenantAddBo bo) {
        return toAjax(iSysTenantService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改系统商户
     */
    @ApiOperation("修改系统商户")
    @PreAuthorize("@ss.hasPermi('system:tenant:edit')")
    @Log(title = "系统商户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody SysTenantEditBo bo) {
        return toAjax(iSysTenantService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除系统商户
     */
   /* @ApiOperation("删除系统商户")
    @PreAuthorize("@ss.hasPermi('system:tenant:remove')")
    @Log(title = "系统商户" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{tenantIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] tenantIds) {
        return toAjax(iSysTenantService.deleteWithValidByIds(Arrays.asList(tenantIds), true) ? 1 : 0);
    }*/
}
