package com.zcxk.charge.web.controller;

import com.zcxk.charge.core.entity.ComdisplayMapLocationEntity;
import com.zcxk.charge.web.service.ComdisplayMapLocationService;
import com.zcxk.core.common.pojo.AjaxMessage;
import com.zcxk.core.oauth2.pojo.LoginUser;
import com.zcxk.core.oauth2.util.UserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 地图坐标页面控制器
 * @author WYY
 * @date 2021-02-24 09:58
 */
@RestController
@RequestMapping("/comdislocation")
@Api(tags = "综合展示--图片坐标")
public class ComdisplayMapLocationController {

    @Autowired
    private ComdisplayMapLocationService comdisplayMapLocationService;

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "保存或修改")
    public AjaxMessage<Integer> save(@ApiParam(value = "地图坐标信息", required = true) @RequestBody ComdisplayMapLocationEntity comdisplayMapLocation){
        LoginUser currentUser = UserUtil.getCurrentUser();
        comdisplayMapLocation.setStatus(1);
        comdisplayMapLocation.setTenantId(currentUser.getTenantId());
        int result= comdisplayMapLocationService.saveOrUpdate(comdisplayMapLocation) ? 1 : 0;
        return AjaxMessage.success( result);
    }

    @RequestMapping(value = "/findMapLocation", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查询地图坐标")
    public AjaxMessage<List<ComdisplayMapLocationEntity>> findMapLocation() {
        LoginUser currentUser = UserUtil.getCurrentUser();
        ComdisplayMapLocationEntity comdisplayMap = new ComdisplayMapLocationEntity();
        comdisplayMap.setTenantId(currentUser.getTenantId());
        List<ComdisplayMapLocationEntity> result = comdisplayMapLocationService.findList(comdisplayMap);
        return AjaxMessage.success( result);
    }

    @ApiOperation(value = "单个编辑")
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ResponseBody
    public  AjaxMessage<Integer> editComdisplayMapLocation(@ApiParam(value = "地图坐标信息", required = true) @RequestBody ComdisplayMapLocationEntity comdisplayMapLocation) {
        int result = comdisplayMapLocationService.updateComdisplayMapLocationById(comdisplayMapLocation) ? 1 : 0;
        return AjaxMessage.success( result);
    }

    @ApiOperation(value = "批量删除")
    @RequestMapping(value = "/deleteByIds", method = RequestMethod.POST)
    @ResponseBody
    public AjaxMessage<Integer> del(@ApiParam(value = "IDS", required = true) @RequestBody Long[] ids) {
        int result = comdisplayMapLocationService.delComdisplayMapLocationByIds(ids) ? 1 : 0;
        return AjaxMessage.success(result);
    }
}
