/*
 * 文 件 名:  GbRegionController
 * 版    权:  华设设计集团股份有限公司
 * 描    述:  <描述>
 * 修 改 人:  lvwenbin
 * 修改时间:  2025/5/8
 * 跟踪单号:  <跟踪单号>
 * 修改单号:  <修改单号>
 * 修改内容:  <修改内容>
 */
package com.huashe.common.data.controller;

import com.huashe.common.data.config.ApiAuth;
import com.huashe.common.data.model.CallResponse;
import com.huashe.common.data.service.RegionService;
import com.huashe.common.domain.model.Region;
import com.huashe.common.exception.BusinessException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 行政区划数据接口
 * <功能详细描述>
 *
 * @author lvwenbin
 * @version [版本号, 2025/5/8]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@RestController
@CrossOrigin(allowedHeaders = "*", allowCredentials = "false")
@RequestMapping("/region")
@Api(value = "GbRegionController", description = "行政区划数据接口")
public class RegionController {
    @Autowired
    private RegionService regionService;

    /**
     * 获取行政区划列表-全部
     */
    @ApiAuth
    @RequestMapping(value = "/getAll", method = RequestMethod.GET)
    @ApiOperation(value = "/getAll", notes = "获取行政区划列表-全部")
    @ApiResponses({ @ApiResponse(code = 200, message = "success"),
        @ApiResponse(code = 400, message = "{code:****,message:'fail'}")
    })
    public CallResponse<List<Region>> getAll() {
        CallResponse<List<Region>> callResponse = new CallResponse<>();

        try {
            List<Region> list = regionService.getAll();
            callResponse.setData(list);
            callResponse.setCode(0);
            callResponse.setMessage("success");
        }
        catch (Exception e) {
            throw new BusinessException(-1, e.getMessage());
        }

        return callResponse;
    }

    /**
     * 条件查询
     */
    @ApiAuth
    @RequestMapping(value = "/getByCondition", method = RequestMethod.GET)
    @ApiOperation(value = "/getByCondition", notes = "查询行政区划-条件查询")
    @ApiResponses({ @ApiResponse(code = 200, message = "success"),
        @ApiResponse(code = 400, message = "{code:****,message:'fail'}")
    })
    public CallResponse<List<Region>> getSubArea(Region param) {
        CallResponse<List<Region>> callResponse = new CallResponse<>();

        try {
            List<Region> list = regionService.getRegion(param);
            callResponse.setData(list);
            callResponse.setCode(0);
            callResponse.setMessage("success");
        }
        catch (Exception e) {
            throw new BusinessException(-1, e.getMessage());
        }

        return callResponse;
    }
}