package com.elephant.framework.galaxy.aroad.module.emergency.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.elephant.framework.galaxy.aroad.module.common.annotation.SysLog;
import com.elephant.framework.galaxy.aroad.module.common.controller.BaseController;
import com.elephant.framework.galaxy.aroad.module.emergency.entity.EmergencyMaterial;
import com.elephant.framework.galaxy.aroad.module.emergency.service.EmergencyMaterialService;
import com.elephant.framework.galaxy.aroad.response.R;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;


/**
 * 应急处置物资
 *
 * @author songwenjie
 * @date 2019-03-21 14:50:12
 */
@RestController
@AllArgsConstructor
@RequestMapping("/emergencymaterial")
public class EmergencyMaterialController extends BaseController {

    private final EmergencyMaterialService emergencyMaterialService;

    /**
     * 分页查询
     *
     * @param page 分页对象
     * @param text 模糊查询
     * @return
     */
    @GetMapping("/page")
    public R getEmergencyMaterialPage(Page page, String text) {
        return new R<>(emergencyMaterialService.getEmergencyMaterialPage(page, text));
    }
    /**
     * 查询所有物资经纬度信息
     */
    @GetMapping("/getlnglat")
    public R getEmergencyMaterialLngLat(){
        return new R<>(emergencyMaterialService.getLngLat());
    }

    /**
     * @Description: 获取队伍车辆坐标信息
     * @auther: XingYuyang
     * @date: 2019-4-9 14:20:33
     * @param: []
     * @return: com.elephant.framework.galaxy.aroad.response.R
     */
    @GetMapping("/coordinates/{teamids}")
    public R getCoordinates(@PathVariable("teamids") String teamIds) {
        return new R<>(emergencyMaterialService.getCoordinates(teamIds));
    }

    /**
     * 通过id查询应急处置物资
     *
     * @param rowId id
     * @return R
     */
    @GetMapping("/{rowId}")
    public R getById(@PathVariable("rowId") Integer rowId) {
        return new R<>(emergencyMaterialService.getById(rowId));
    }

    /**
     * @Description: 获取队伍列表
     * @Param:
     * @return:
     * @Author: XingYuyang
     * @Date: 2019-04-15 10:08:18
     */
    @GetMapping("/getteams")
    public R getTeams() {
        return new R<>(emergencyMaterialService.getTeams());
    }

    /**
     * 新增应急处置物资
     *
     * @param emergencyMaterial 应急处置物资
     * @return R
     */
    @SysLog("新增应急处置物资")
    @PostMapping
    public R save(@RequestBody EmergencyMaterial emergencyMaterial) {
        return new R<>(emergencyMaterialService.save(emergencyMaterial));
    }

    /**
     * 修改应急处置物资
     *
     * @param emergencyMaterial 应急处置物资
     * @return R
     */
    @SysLog("修改应急处置物资")
    @PutMapping
    public R updateById(@RequestBody EmergencyMaterial emergencyMaterial) {
        return new R<>(emergencyMaterialService.updateById(emergencyMaterial));
    }

    /**
     * 通过id删除应急处置物资
     *
     * @param rowId id
     * @return R
     */
    @SysLog("删除应急处置物资")
    @DeleteMapping("/{rowId}")
    public R removeById(@PathVariable Integer rowId) {
        return new R<>(emergencyMaterialService.removeById(rowId));
    }
    /**
     * 通过ID查询应急物资集
     */
    @GetMapping("/getbyids")
    public R getByIds(@RequestParam("ids") String ids){
        return new R<>(emergencyMaterialService.getByIds(Arrays.asList(ids.split(","))));
    }
}
