package com.microservices.zone.specialProject.controller;

import com.alibaba.fastjson2.JSONObject;
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.project.domain.vo.ZoneProjectSearchVo;
import com.microservices.zone.resource.domain.vo.ZoneResourceSearchVo;
import com.microservices.zone.specialProject.domain.ZoneSpecialProjectRelevancy;
import com.microservices.zone.specialProject.domain.vo.CommonTypeVo;
import com.microservices.zone.specialProject.domain.vo.ZoneSpecialProjectRelevancyInputVo;
import com.microservices.zone.specialProject.domain.vo.ZoneSpecialProjectRelevancySearchVo;
import com.microservices.zone.specialProject.domain.vo.ZoneSpecialProjectRelevancyUpdateVo;
import com.microservices.zone.specialProject.service.IZoneSpecialProjectRelevancyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 特色专区专项项目关联关系Controller
 *
 * @author otto
 * @date 2024-10-26
 */
@RestController
@RequestMapping("/specialProjectRelevancy")
@Api(tags = "特色专区专项项目关联关系接口")
public class ZoneSpecialProjectRelevancyController extends BaseController {
    @Autowired
    private IZoneSpecialProjectRelevancyService zoneSpecialProjectRelevancyService;

    /**
     * 查询特色专区专项项目关联关系列表
     */
    @RequiresPermissions("zone:specialProjectRelevancy:list")
    @GetMapping("/list")
    @ApiOperation("查询特色专区专项项目关联关系列表")
    public GenericsTableDataInfo<ZoneSpecialProjectRelevancy> list(@Validated ZoneSpecialProjectRelevancySearchVo zoneSpecialProjectRelevancySearchVo) {
        startPage();
        List<ZoneSpecialProjectRelevancy> list = zoneSpecialProjectRelevancyService.selectZoneSpecialProjectRelevancyList(zoneSpecialProjectRelevancySearchVo.toZoneSpecialProjectRelevancySearchVo());
        return getGenericsDataTable(list);
    }

    /**
     * 获取特色专区专项项目关联关系详细信息
     */
    @RequiresPermissions("zone:specialProjectRelevancy:query")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取特色专区专项项目关联关系详细信息")
    public GenericsAjaxResult<ZoneSpecialProjectRelevancy> getInfo(@PathVariable("id") Long id) {
        return genericsSuccess(zoneSpecialProjectRelevancyService.selectZoneSpecialProjectRelevancyById(id));
    }

    /**
     * 新增特色专区专项项目关联关系
     */
    @RequiresPermissions("zone:specialProjectRelevancy:add")
    @Log(title = "特色专区专项项目关联关系", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增特色专区专项项目关联关系")
    public AjaxResult add(@RequestBody @Validated ZoneSpecialProjectRelevancyInputVo zoneSpecialProjectRelevancyInputVo) {
        return toAjax(zoneSpecialProjectRelevancyService.insertZoneSpecialProjectRelevancy(zoneSpecialProjectRelevancyInputVo));
    }

    /**
     * 修改特色专区专项项目关联关系
     */
    @RequiresPermissions("zone:specialProjectRelevancy:edit")
    @Log(title = "特色专区专项项目关联关系", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改特色专区专项项目关联关系")
    public AjaxResult edit(@RequestBody @Validated ZoneSpecialProjectRelevancyUpdateVo zoneSpecialProjectRelevancyUpdateVo) {
        return toAjax(zoneSpecialProjectRelevancyService.updateZoneSpecialProjectRelevancy(zoneSpecialProjectRelevancyUpdateVo));
    }

    /**
     * 删除特色专区专项项目关联关系
     */
    @RequiresPermissions("zone:specialProjectRelevancy:remove")
    @Log(title = "特色专区专项项目关联关系", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除特色专区专项项目关联关系")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(zoneSpecialProjectRelevancyService.deleteZoneSpecialProjectRelevancyByIds(ids));
    }

    @GetMapping("/ZoneSpecialProjectRelevancyType/list")
    @ApiOperation(value = "专项项目关联类型列表")
    public List<CommonTypeVo> zoneSpecialProjectRelevancyTypeList() {
        return zoneSpecialProjectRelevancyService.selectZoneSpecialProjectRelevancyTypeList();
    }

    /**
     * 查询特色专区资源聚合列表
     */
    @RequiresPermissions("zone:specialProjectRelevancy:resourceList")
    @GetMapping("/{specialProjectId}/resourceList")
    @ApiOperation("查询专区下资源聚合列表")
    public GenericsTableDataInfo<JSONObject> resourceList(
            @PathVariable("specialProjectId") Long specialProjectId,
            ZoneResourceSearchVo zoneResourceSearchVo) {
        return zoneSpecialProjectRelevancyService.selectZoneResourceList(specialProjectId, zoneResourceSearchVo.toZoneResource());
    }

    /**
     * 查询特色专区项目聚合列表
     */
    @RequiresPermissions("zone:specialProjectRelevancy:projectList")
    @GetMapping("/{specialProjectId}/projectList")
    @ApiOperation("查询专区下项目聚合列表")
    public GenericsTableDataInfo<JSONObject> projectList(
            @PathVariable("specialProjectId") Long specialProjectId,
            ZoneProjectSearchVo zoneProjectSearchVo) {
        return zoneSpecialProjectRelevancyService.selectZoneProjectList(specialProjectId, zoneProjectSearchVo, false);
    }
}
