package cn.pluss.platform.controller.sys;

import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.dto.RegionReflectDTO;
import cn.pluss.platform.region.RegionReflectService;
import cn.pluss.platform.vo.RegionReflectVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author djh
 * 通道地区对应页面
 */
@Controller
@RequestMapping("/regionReflect")
public class RegionReflectController {

    @Autowired
    private RegionReflectService regionReflectService;

    @GetMapping("/list")
    public String list() {
        return "/sys/region/regionReflectList";
    }

    @GetMapping("/pageData")
    @ResponseBody
    public Result<Object> pageData(Page<RegionReflectVO> page, String province, String city, String code) {
        val result = regionReflectService.pageRegionReflect(page, province, city, code);
        return ResultGenerator.genSuccessResult(result);
    }



    @GetMapping("/edit/{type}")
    public String edit(HttpServletRequest request, @PathVariable("type") String type, String regionSrc) {
        request.setAttribute("type", type);
        request.setAttribute("regionSrc", regionSrc);

        return "/sys/region/regionReflectEdit";
    }

    @GetMapping("/listProvince/{type}")
    @ResponseBody
    public Result<Object> listProvince(@PathVariable("type") String type) {
        val result = regionReflectService.listProvince(type);

        return ResultGenerator.genSuccessResult(result);
    }

    @GetMapping("/listCity/{type}/{province}")
    @ResponseBody
    public Result<Object> listCity(@PathVariable("type") String type, @PathVariable("province") String province) {
        val result = regionReflectService.listCity(type, province);

        return ResultGenerator.genSuccessResult(result);
    }

    @GetMapping("/listArea/{type}/{province}/{city}")
    @ResponseBody
    public Result<Object> listArea(@PathVariable("type") String type, @PathVariable("province") String province, @PathVariable("city") String city) {
        val result = regionReflectService.listArea(type, city, province);

        return ResultGenerator.genSuccessResult(result);
    }

    @PostMapping("/save")
    @ResponseBody
    public Result<Object> saveReflect(RegionReflectDTO inputData) {
        regionReflectService.saveReflect(inputData);

        return ResultGenerator.genSuccessResult("保存成功", null);
    }
}
