package com.microservices.zone.resource.controller;

import com.microservices.common.core.web.controller.BaseController;
import com.microservices.common.core.web.domain.AjaxResult;
import com.microservices.common.core.web.domain.GenericsAjaxResult;
import com.microservices.common.core.web.page.GenericsTableDataInfo;
import com.microservices.common.log.annotation.Log;
import com.microservices.common.log.enums.BusinessType;
import com.microservices.common.security.annotation.RequiresPermissions;
import com.microservices.zone.resource.domain.ZoneResourceType;
import com.microservices.zone.resource.domain.vo.*;
import com.microservices.zone.resource.service.IZoneResourceTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 特色专区资源类别Controller
 *
 * @author otto
 * @date 2023-06-27
 */
@RestController
@RequestMapping("/resourceType")
@Api(tags = "特色专区资源类别接口")
public class ZoneResourceTypeController extends BaseController {
    @Autowired
    private IZoneResourceTypeService zoneResourceTypeService;

    /**
     * 查询特色专区资源类别列表
     */
    @RequiresPermissions("zone:resourceType:list")
    @GetMapping("/list")
    @ApiOperation("查询特色专区资源类别列表")
    public GenericsTableDataInfo<ZoneResourceType> list(ZoneResourceTypeSearchVo zoneResourceTypeSearchVo) {
        startPage();
        List<ZoneResourceType> list = zoneResourceTypeService.selectZoneResourceTypeList(zoneResourceTypeSearchVo.toZoneResourceType(), false);
        return getGenericsDataTable(list);
    }

    /**
     * 获取特色专区资源类别详细信息
     */
    @RequiresPermissions("zone:resourceType:query")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取特色专区资源类别详细信息")
    public GenericsAjaxResult<ZoneResourceType> getInfo(@PathVariable("id") Long id) {
        return genericsSuccess(zoneResourceTypeService.selectZoneResourceTypeById(id));
    }

    /**
     * 根据文件id获取专区下资源类别
     */
    @GetMapping(value = "/zone/{zoneId}/getResourceTypeByFileId/{fileId}")
    @ApiOperation("根据文件id获取专区下资源类别")
    public GenericsAjaxResult<ZoneResourceType> getResourceTypeByFileId(@PathVariable("zoneId") Long zoneId, @PathVariable("fileId") Long fileId) {
        return genericsSuccess(zoneResourceTypeService.getResourceTypeByFileId(zoneId, fileId));
    }

    /**
     * 根据文件id列表获取专区下资源类别
     */
    @GetMapping(value = "/zone/{zoneId}/getResourceTypeByFileIds/{fileIds}")
    @ApiOperation("根据文件id列表获取专区下文件对应资源类别列表")
    public GenericsAjaxResult<List<ZoneResourceFileVo>> getResourceTypeByFileIds(@PathVariable("zoneId") Long zoneId, @PathVariable("fileIds") String fileIds) {
        return genericsSuccess(zoneResourceTypeService.getResourceTypeByFileIds(zoneId, fileIds));
    }

    /**
     * 修改当前文件对应的资源类别
     */
    @RequiresPermissions("zone:resourceType:edit")
    @Log(title = "修改当前文件对应的资源类别", businessType = BusinessType.UPDATE)
    @PutMapping("/updateResourceTypeByFileId")
    @ApiOperation("修改当前文件对应的资源类别")
    public AjaxResult updateResourceTypeByFileId(@RequestBody TargetResourceTypeNameVo targetResourceTypeNameVo) {
        return toAjax(zoneResourceTypeService.updateResourceTypeByFileId(targetResourceTypeNameVo));
    }

    /**
     * 新增特色专区资源类别
     */
    @RequiresPermissions("zone:resourceType:add")
    @Log(title = "特色专区资源类别", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增特色专区资源类别")
    public AjaxResult add(@RequestBody ZoneResourceTypeInputVo zoneResourceTypeInputVo) {
        return toAjax(zoneResourceTypeService.insertZoneResourceType(zoneResourceTypeInputVo));
    }

    /**
     * 修改特色专区资源类别
     */
    @RequiresPermissions("zone:resourceType:edit")
    @Log(title = "特色专区资源类别", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改特色专区资源类别")
    public AjaxResult edit(@RequestBody ZoneResourceTypeUpdateVo zoneResourceTypeUpdateVo) {
        return toAjax(zoneResourceTypeService.updateZoneResourceType(zoneResourceTypeUpdateVo));
    }

    /**
     * 删除特色专区资源类别
     */
    @RequiresPermissions("zone:resourceType:remove")
    @Log(title = "特色专区资源类别", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除特色专区资源类别")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(zoneResourceTypeService.deleteZoneResourceTypeByIds(ids));
    }
}
