package com.ruoyi.business.controller;

import com.ruoyi.business.domain.ServiceBusiness;
import com.ruoyi.business.domain.ServiceBusinessVo;
import com.ruoyi.business.service.IServiceBusinessService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 对外业务服务Controller
 * 
 * @author wzq
 * @date 2024-01-10
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/dataExchange/serviceBusiness")
@RequiredArgsConstructor
public class ServiceBusinessController extends BaseController {

    private final IServiceBusinessService serviceBusinessService;

    /**
     * 查询对外业务服务列表
     */
    @RequiresPermissions("business_serviceBusiness_list")
    @GetMapping
    public AjaxResult list(ServiceBusiness serviceBusiness) {
        List<ServiceBusiness> list = serviceBusinessService.selectServiceBusinessList(serviceBusiness);
        return success(list);
    }

    /**
     * 查询对外业务服务列表(分页)
     */
    @RequiresPermissions("business_serviceBusiness_list")
    @GetMapping("/list")
    public TableDataInfo pageList(ServiceBusiness serviceBusiness) {
        startPage();
        List<ServiceBusiness> list = serviceBusinessService.selectServiceBusinessList(serviceBusiness);
        return getDataTable(list);
    }

    /**
     * 获取对外业务服务详细信息
     */
    @RequiresPermissions("business_serviceBusiness_query")
    @GetMapping(value = "/{id}")
    public AjaxResult getServiceBusinessById(@PathVariable("id") Long id) {
        return success(serviceBusinessService.selectServiceBusinessById(id));
    }

    /**
     * 新增对外业务服务
     */
    @RequiresPermissions("business_serviceBusiness_add")
    @Log(title = "对外业务服务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult addServiceBusiness(@RequestBody ServiceBusiness serviceBusiness) {
        serviceBusiness.setDeptIdPath(SecurityUtils.getDeptIdPath());
        serviceBusiness.setDeptName(SecurityUtils.getDeptName());
        serviceBusiness.setCreateUserId(SecurityUtils.getUserId());
        serviceBusiness.setCreateBy(SecurityUtils.getUsername());
        return toAjax(serviceBusinessService.insertServiceBusiness(serviceBusiness));
    }

    /**
     * 修改对外业务服务
     */
    @RequiresPermissions("business_serviceBusiness_edit")
    @Log(title = "对外业务服务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult updateServiceBusiness(@RequestBody ServiceBusiness serviceBusiness) {
        serviceBusiness.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(serviceBusinessService.updateServiceBusiness(serviceBusiness));
    }

    /**
     * 批量删除对外业务服务
     */
    @RequiresPermissions("business_serviceBusiness_delete")
    @Log(title = "对外业务服务", businessType = BusinessType.DELETE)
    @DeleteMapping("deleteByIds/{ids}")
    public AjaxResult delete(@PathVariable Long[] ids) {
        return toAjax(serviceBusinessService.deleteServiceBusinessByIds(ids));
    }

    /**
     * 删除对外业务服务
     */
    @RequiresPermissions("business_serviceBusiness_delete")
    @Log(title = "对外业务服务", businessType = BusinessType.DELETE)
    @DeleteMapping("deleteById/{id}")
    public AjaxResult delete(@PathVariable Long id) {
        return toAjax(serviceBusinessService.deleteServiceBusinessById(id));
    }

    /**
     * 获取对外业务服务树列表
     */
    @RequiresPermissions("business_serviceBusiness_list")
    @GetMapping("/grantTree")
    public AjaxResult deptTree(ServiceBusiness serviceBusiness)
    {
        return success(serviceBusinessService.selectGrantTreeList(serviceBusiness));
    }


}
