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.common.service.IZoneAsyncService;
import com.microservices.zone.resource.domain.vo.*;
import com.microservices.zone.resource.service.IZoneResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 特色专区资源聚合Controller
 *
 * @author otto
 * @date 2023-06-27
 */
@RestController
@RequestMapping("/resource")
@Api(tags = "特色专区资源接口")
public class ZoneResourceController extends BaseController {
    @Autowired
    private IZoneResourceService zoneResourceService;
    @Autowired
    private IZoneAsyncService zoneAsyncService;

    /**
     * 查询特色专区资源聚合列表
     */
    @RequiresPermissions("zone:resource:list")
    @GetMapping("/list")
    @ApiOperation("查询特色专区资源聚合列表")
    public GenericsTableDataInfo<ZoneResourceDataVo> list(ZoneResourceSearchVo zoneResourceSearchVo) {
        startPage();
        return zoneResourceService.selectZoneResourceList(zoneResourceSearchVo.toZoneResource());
    }

    /**
     * 获取特色专区资源聚合详细信息
     */
    @RequiresPermissions("zone:resource:query")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取特色专区资源聚合详细信息")
    public GenericsAjaxResult<ZoneResourceDataVo> getInfo(@PathVariable("id") Long id) {
        return genericsSuccess(zoneResourceService.selectZoneResourceDataById(id));
    }

    /**
     * 新增特色专区资源聚合
     */
    @RequiresPermissions("zone:resource:add")
    @Log(title = "特色专区资源聚合", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增特色专区资源聚合")
    public AjaxResult add(@RequestBody ZoneResourceInputVo zoneResourceInputVo) {
        return success(zoneResourceService.insertZoneResource(zoneResourceInputVo));
    }

    /**
     * 修改特色专区资源聚合
     */
    @RequiresPermissions("zone:resource:edit")
    @Log(title = "特色专区资源聚合", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改特色专区资源聚合")
    public AjaxResult edit(@RequestBody ZoneResourceUpdateVo zoneResourceUpdateVo) {
        return success(zoneResourceService.updateZoneResource(zoneResourceUpdateVo));
    }

    /**
     * 审核特色专区资源
     */
    @RequiresPermissions("zone:resource:audit")
    @Log(title = "审核特色专区资源", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    @ApiOperation("审核特色专区资源")
    public AjaxResult audit(@RequestBody ZoneResourceAuditVo zoneResourceAuditVo) {
        return toAjax(zoneResourceService.auditZoneResource(zoneResourceAuditVo));
    }

    /**
     * 自动识别专区资源对应类型
     */
    @RequiresPermissions("zone:resource:asyncType")
    @Log(title = "自动识别专区资源对应类型", businessType = BusinessType.UPDATE)
    @PutMapping("/asyncUpdateType")
    @ApiOperation("自动识别专区资源对应类型")
    public AjaxResult asyncUpdateType() {
        zoneAsyncService.asyncUpdateType();
        return success("已开始进行自动识别，预计需要5分钟左右完成");
    }

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