package io.renren.modules.admin.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.admin.entity.AttendersEntity;
import io.renren.modules.admin.entity.HotalEntity;
import io.renren.modules.admin.service.AttendersService;
import io.renren.modules.admin.service.HotalService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * VIEW
 *
 * @author huwhois
 * @email huwhois@163.com
 * @date 2021-06-08 09:39:30
 */
@RestController
@RequestMapping("admin/hotal")
public class HotalController {
    @Autowired
    private HotalService hotalService;
    @Autowired
    private AttendersService attendersService;

    /**
     * 列表
     */
    @RequestMapping("/list/{mid}")
    @RequiresPermissions("admin:hotal:list")
    public R list(@RequestParam Map<String, Object> params, @PathVariable("mid") Long mid){
        PageUtils page = hotalService.queryPage(params, mid);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{aid}")
    @RequiresPermissions("admin:hotal:info")
    public R info(@PathVariable("aid") Long aid){
		HotalEntity hotal = hotalService.getById(aid);

        return R.ok().put("hotal", hotal);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("admin:hotal:update")
    public R update(@RequestBody HotalEntity hotal){
		AttendersEntity attenders = attendersService.getById(hotal.getAid());
        attenders.setHotelType(hotal.getHotelType());
        attenders.setIsShare(hotal.getIsShare());
        attenders.setRoomType(hotal.getRoomType());
        attenders.setCheckInDate(hotal.getCheckInDate());
        attenders.setCheckOutDate(hotal.getCheckOutDate());

        attendersService.updateById(attenders);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete/{aid}")
    @RequiresPermissions("admin:hotal:delete")
    public R delete(@PathVariable("aid") Long aid){
        AttendersEntity attenders = attendersService.getById(aid);
        attenders.setHotelType(0);
        attenders.setIsShare(0);
        attenders.setRoomType(0);
        attenders.setCheckInDate(null);
        attenders.setCheckOutDate(null);

        attendersService.updateById(attenders);
        return R.ok();
    }

}
