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

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.EmergencyTeamEquipment;
import com.elephant.framework.galaxy.aroad.module.emergency.service.EmergencyTeamEquipmentService;
import com.elephant.framework.galaxy.aroad.response.R;
import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Transformer;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


/**
 * 获取队伍装备基础信息
 *
 * @author XingYuyang
 * @date 2019-04-04 11:03:17
 */
@RestController
@AllArgsConstructor
@RequestMapping("/emergencyteamequipment")
public class EmergencyTeamEquipmentController extends BaseController {

    private final EmergencyTeamEquipmentService emergencyTeamEquipmentService;

    /**
     * 分页查询
     *
     * @param page                   分页对象
     * @param emergencyTeamEquipment 获取队伍装备基础信息
     * @return
     */
    @GetMapping("/page")
    public R getEmergencyTeamEquipmentPage(Page page, EmergencyTeamEquipment emergencyTeamEquipment) {
        return new R<>(emergencyTeamEquipmentService.page(page, Wrappers.query(emergencyTeamEquipment)));
    }

    /**
     * @Description: 获取队伍装备的坐标信息
     * @Param:
     * @return:
     * @Author: XingYuyang
     * @Date: 2019-04-04 11:08:37
     */
    @GetMapping("/coordinates")
    public R getCoordinates() {
        return new R<>(emergencyTeamEquipmentService.getCoordinates());
    }

    /**
     * 通过id查询获取队伍装备基础信息
     *
     * @param rowId id
     * @return R
     */
    @GetMapping("/{rowId}")
    public R getById(@PathVariable("rowId") Integer rowId) {
        return new R<>(emergencyTeamEquipmentService.getById(rowId));
    }

    /**
     * @Description: 通过多ID查询队伍装备基础信息
     * @Param: ids
     * @return: com.elephant.framework.galaxy.aroad.response.R
     * @Author: XingYuyang
     * @Date: 2019-04-04 16:41:26
     */
    @RequestMapping(value = "/equipmentinfobyids/{ids}", method = {RequestMethod.GET})
    @ResponseBody
    public R getEquipmentInfoByIds(@PathVariable("ids") String ids) {
        List<String> idsStringList = Arrays.asList(ids.split(","));
        List<Integer> idsList = new ArrayList<>();
        CollectionUtils.collect(idsStringList, new Transformer() {
            public Object transform(Object o) {
                return Integer.valueOf(o.toString());
            }
        }, idsList);
        return new R<>(emergencyTeamEquipmentService.listByIds(idsList));
    }

    /**
     * 新增获取队伍装备基础信息
     *
     * @param emergencyTeamEquipment 获取队伍装备基础信息
     * @return R
     */
    @SysLog("新增获取队伍装备基础信息")
    @PostMapping
    public R save(@RequestBody EmergencyTeamEquipment emergencyTeamEquipment) {
        return new R<>(emergencyTeamEquipmentService.save(emergencyTeamEquipment));
    }

    /**
     * 修改获取队伍装备基础信息
     *
     * @param emergencyTeamEquipment 获取队伍装备基础信息
     * @return R
     */
    @SysLog("修改获取队伍装备基础信息")
    @PutMapping
    public R updateById(EmergencyTeamEquipment emergencyTeamEquipment) {
        return new R<>(emergencyTeamEquipmentService.updateById(emergencyTeamEquipment));
    }

    /**
     * 通过id删除获取队伍装备基础信息
     *
     * @param rowId id
     * @return R
     */
    @SysLog("删除获取队伍装备基础信息")
    @DeleteMapping("/{rowId}")
    public R removeById(@PathVariable Integer rowId) {
        return new R<>(emergencyTeamEquipmentService.removeById(rowId));
    }

}
