package com.ruoyi.web.controller.system;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.domain.dto.villageSpecial.VillageSpecialAddRequest;
import com.ruoyi.web.domain.dto.villageSpecial.VillageSpecialEditRequest;
import com.ruoyi.web.domain.dto.villageSpecial.VillageSpecialQueryRequest;
import com.ruoyi.web.domain.entity.ProductionData;
import com.ruoyi.web.domain.vo.VillageSpecial.BaseVillageSpecialVO;
import com.ruoyi.web.service.VillageSpecialService;
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;
import java.util.Map;

import static com.ruoyi.common.core.domain.AjaxResult.error;
import static com.ruoyi.common.core.domain.AjaxResult.success;

@Api(tags = "特色产业管理")
@RestController
@RequestMapping("/system/village/special")
public class VillageSpecialController {

    @Autowired
    private VillageSpecialService villageSpecialService;

    /**
     * 添加特色产业
     *
     * @param villageSpecialAddRequest
     * @return
     */
    @ApiOperation("添加特色产业")
    @PostMapping("/add")
    public AjaxResult addVillageSpecial(@RequestBody VillageSpecialAddRequest villageSpecialAddRequest) {
        if (villageSpecialAddRequest == null) {
            return error("请求参数为空");
        }
        Integer id = villageSpecialService.addVillageSpecial(villageSpecialAddRequest);
        return success(id);
    }

    /**
     * 删除特色产业
     *
     * @param paramsMap
     * @return
     */
    @ApiOperation("删除特色产业")
    @PostMapping("/delete")
    public AjaxResult deleteVillageSpecial(@RequestBody Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        if (StrUtil.isBlank(ids)) {
            return error("请求参数为空");
        }
        boolean b = villageSpecialService.deleteVillageSpecial(ids);
        if (b) {
            return success("删除成功");
        }
        return error("删除失败");
    }


    /**
     * 编辑特色产业
     *
     * @param villageSpecialEditRequest
     * @return
     */
    @ApiOperation("编辑特色产业")
    @PostMapping("/edit")
    public AjaxResult editVillageSpecial(@RequestBody VillageSpecialEditRequest villageSpecialEditRequest) {
        if (villageSpecialEditRequest == null) {
            return error("请求参数为空");
        }
        villageSpecialService.editVillageSpecial(villageSpecialEditRequest);
        return AjaxResult.success();
    }


    /**
     * 根据id获取特色产业
     *
     * @param id
     * @return
     */
    @ApiOperation("根据id获取特色产业")
    @GetMapping("/get")
    public AjaxResult getVillageSpecialById(@RequestParam int id) {
        if (ObjectUtil.isEmpty(id)) {
            return error("请求参数为空");
        }
        BaseVillageSpecialVO villageSpecialVO = villageSpecialService.getVillageSpecialById(id);
        return success(villageSpecialVO);
    }

    /**
     * 分页获取特色产业列表
     *
     * @param villageSpecialQueryRequest
     * @return
     */
    @ApiOperation("分页获取特色产业列表")
    @PostMapping("/list/page")
    public AjaxResult listVillageSpecialByPage(@RequestBody VillageSpecialQueryRequest villageSpecialQueryRequest) {
        if (villageSpecialQueryRequest == null) {
            return error("请求参数为空");
        }
        Page<BaseVillageSpecialVO> listVillageSpecialByPage = villageSpecialService.getListVillageSpecialByPage(villageSpecialQueryRequest);
        return success(listVillageSpecialByPage);
    }

    /**
     * 根据id获取特色产业的产品/菜品列表
     *
     * @param id
     * @return
     */
    @ApiOperation("获取特色产业的产品/菜品列表")
    @GetMapping("/get/product/list")
    public AjaxResult getVillageSpecialProductList(@RequestParam int id) {
        if (ObjectUtil.isEmpty(id)) {
            return error("请求参数为空");
        }
        List<ProductionData> productDataList = villageSpecialService.getProductDataList(id);
        return success(productDataList);
    }

}
