package com.zjrs.ggfw.xcx.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.mohrss.leaf.core.framework.web.controller.AjaxResponse;
import com.zjrs.ggfw.xcx.bpo.Gcj02BPO;
import com.zjrs.ggfw.xcx.dto.Gcj02DTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;

@Api("火星坐标系")
@RestController
@RequestMapping("/api/xcx/gcj02")
public class Gcj02Controller {
    /**
     * 日志
     */
    private static final Logger LOG = LoggerFactory.getLogger(Gcj02Controller.class);
    
    @Resource
    private Gcj02BPO gcj02BPO;
    
    @ApiOperation(value = "获取当前经纬度地址记录", notes = "获取当前经纬度地址记录")
    @PostMapping("/getRecord")
    public AjaxResponse getRecord(@RequestBody @Validated Gcj02DTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
    	if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = gcj02BPO.getRecord(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    
    @ApiOperation(value = "保存当前经纬度地址记录", notes = "保存当前经纬度地址记录")
    @PostMapping("/saveRecord")
    public AjaxResponse saveRecord(@RequestBody @Validated Gcj02DTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
    	if(bindingResult.hasErrors()) {
    		ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
    	}
        try {
        	ajaxResponse = gcj02BPO.saveRecord(dto);
        } catch (Exception e) {
            LOG.error(e.toString());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
}